Matlab etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Matlab etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

24 Mayıs 2012 Perşembe

Matlab - Traffic Sign Detection

GOAL: Implement a traffic sign detection program which detects location of the traffic sign(s) on a given image.


       Input image:                                                                                                                         Output image:




ALGORITHM

To detect a traffic sign in an image, the algorithm follows these steps:
1) Color detection
2) Conversion to grayscale
3) Edge and line detection with Hough transforms
4) Optimization of edges
5) Highlighting the found traffic signs in the image


Download

26 Nisan 2012 Perşembe

How to extract the regions with different colors from the input image

I developed a MATLAB function color_extract that extracts the regions with different colors from
the input image using a color model different than RGB. The purpose of it is to use different color models.




Processing of Color Images:

1. Convert to another color model YIQ, HSV, etc.
(You can use matlab functions ex: rgb2hsv)
2. Process the image, make changes.
3. Then convert it back to RGB.
(You can use matlab functions ex: hsv2rgb)












Note: I used HSV. To obtain Hue values easily, you can use MS Paint by clicking "EditColors".























Download Code

19 Mart 2012 Pazartesi

Matlab - histeq implementation

Matlab da histogram equalization için kullanılan histeq fonksiyonunun implementasyonu:

***F bir gray scale input image****

function image_histeq(F)

I = imread(F);

%histeq
J = histeq(I);

%Output image of our algorithm and its histogram

width = size(I,1);
height = size(I,2);
MN = width * height;

Hist = uint8(zeros(width , height));

frequency = zeros(256 , 1);

probability = zeros(256,1);


for i = 1 : width
for j = 1 : height
value = I(i , j);
frequency(value + 1) = frequency(value + 1) + 1;
probability(value + 1) = frequency(value + 1) / MN;
end
end

sum = 0;
bits = 255;

probCount = zeros(256 , 1);

cum = zeros(256 , 1);


output = zeros(256 , 1);

for i = 1 : size(probability)
sum = sum + frequency(i);
cum(i) = sum;
probCount(i) = cum(i) / MN;
output(i) = round(probCount(i) * bits);
end


for i = 1 : width
for j = 1 : height

Hist(i,j) = output(I(i , j) + 1);

end
end

%display all

subplot(3,2,1);
imshow(I);
title('Input Image');
subplot(3,2,2);
imhist(I);
title('Input image histogram');
subplot(3,2,3);
imshow(J);
title('Output image of histeq function');
subplot(3,2,4);
imhist(J);
title('histeq function histogram');
subplot(3,2,5);
imshow(Hist);
title('Output image of our algorithm');
subplot(3,2,6);
imhist(Hist);
title('our algorithm histogram');


return

Download Code

Matlab - filter Implementation

filter2 fonkiyonuyla yapılan bluring işleminin implementasyonu:

***filter2 ve algoritmanın output imageları aynı pencerede subplot kullanarak gösteriliyor***
**** 3 X 3 bir filter kullanılıyor****
***filter size arttıkça bluring artar***
*** F input image: bir gray scale image***


% Main function
function image_filter(F)

%filter2
I = imread(F);
filt = ones(3 , 3) / 9;
res = filter2(filt, I, 'same');
J = uint8(res);

%our filtering algorithm

height = size(I, 1);
width = size(I, 2);

a = zeros(height + 2, width + 2, 'uint8');


for i = 2 : height + 1
for j = 2 : width + 1
a (i, j) = I(i - 1, j - 1);
end
end
b = zeros(height, width, 'uint8');

for i = 1 : height
for j=1 : width
avg = mean2(a(i : i + 2, j : j + 2));
b(i , j) = avg;
end
end

%display all

subplot(2,2,1);
imshow(I);
title('Input Image');
subplot(2,2,2);
imshow(J);
title('Output image of filter2 function');
subplot(2,2,3);
imshow(b);
title('Output image of our function');

return

Download Code

3 Mart 2012 Cumartesi

MatLab - Flip & Rotate & Resize image

% Main function
function main()
global height;
global width;
global x;

x = imread('sample_img.jpg');

% display the original image
figure
image(x);
title('original');

height = size(x, 1);
width = size(x, 2);

flipVertical();
flipHorizantal();
rotateLeft();
rotateRight();
resizeImage();

return

% flips input image vertically
function flipVertical()
global height;
global width;
global x;
y = zeros(height, width, 3, 'uint8');

for i=1:height
for j=1:width
for k=1:3
y(height - i + 1, j, k) = x(i, j, k);
end
end
end
imwrite(y, 'flipVertical.jpg', 'jpg');
figure
image(y);
title('vertical flip');
return

% flips input image horizontally
function flipHorizantal()
global height;
global width;
global x;
y = zeros(height, width, 3, 'uint8');

for i=1:height
for j=1:width
for k=1:3
y(i, width - j + 1, k) = x(i, j, k);
end
end
end
imwrite(y, 'flipHorizontal.jpg', 'jpg');
figure
image(y);
title('horizontal flip');
return

% rotates input image to left
function rotateLeft()
global height;
global width;
global x;
y = zeros(width, height, 3, 'uint8');

for i=1:width
for j=1:height
for k=1:3
y(i, j, k) = x(j, width-i+1, k);

end
end
end
imwrite(y, 'rotateLeft.jpg', 'jpg');
figure
image(y);
title('rotate left');
return

% rotates input image to right
function rotateRight()
global height;
global width;
global x;
y = zeros(width, height, 3, 'uint8');

for i=1:width
for j=1:height
for k=1:3
y(i, j, k) = x(height - j + 1, i, k);
end
end
end
imwrite(y, 'rotateRight.jpg', 'jpg');
figure
image(y);
title('rotate right');
return

% resizes input image to half by keeping aspect ratio
function resizeImage()
global x;
y = zeros(201, 250, 3, 'uint8');
for i=1:201
for j=1:249
for k=1:3
y(i, j, k) = x(i * 2, j * 2, k);
end
end
end

imwrite(y, 'resizeImage.jpg', 'jpg');
figure
image(y);
title('resized');

return

Download Code