how to write code for given algorithm
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
to write code for this given algorithm if my image is pic.jpg
my image is gray image.
FOR all rows in image:
FOR i from 1 to (row length-1):
IF gray value(pixeli) -
gray value(pixeli+1) > edge Threshold THEN
set pixeli=WHITE
ELSE
set pixeli=BLACK
END IF
END
END
this is for only rows but i hv to do it both horizontally and vertically
0 Kommentare
Antworten (1)
nug
am 6 Apr. 2016
Are you trying to get someone to do your homework? Anyways you would first need to read the image using 'imread'. Use 'size' to figure out the number of rows and columns. If I represents your image, size(I,1) gives you number of rows and size(I,2) number of columns. Then based on your threshold you can set the pixel value to either 255(white) or 0(black).
Here is the sample code
I = imread('pic.jpg');
imshow(I);
for i= 1:size(I,1)
for j = 1:size(I,2)
if I(i,j) > threshold
I(i,j) = 255;
else
I(i,j) = 0;
end
end
end
figure, imshow(I)
or as an alternative you could use 'graythresh' from matlab to do the same.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!