how to write code for given algorithm

조회 수: 2 (최근 30일)
ramya sharma
ramya sharma 2016년 4월 6일
편집: Walter Roberson 2016년 4월 7일
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

답변 (1개)

nug
nug 2016년 4월 6일
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.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by