how to write code for given algorithm

1 visualización (últimos 30 días)
ramya sharma
ramya sharma el 6 de Abr. de 2016
Editada: Walter Roberson el 7 de Abr. de 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

Respuestas (1)

nug
nug el 6 de Abr. de 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.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by