MATLAB Answers

how to write code for given algorithm

11 views (last 30 days)
ramya sharma
ramya sharma on 6 Apr 2016
Edited: Walter Roberson on 7 Apr 2016
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 Comments

Sign in to comment.

Answers (1)

nug
nug on 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 Comments

Sign in to comment.

Sign in to answer this question.

Tags


Translated by