Note : I have made the code assuming image is given in the form of matrix haiving pixel value between 0 and 255. So, I have created the matrix with no of rows =R and no of columns =C having each pixel rabdom value between 0 and 255.
Code:
R=3; % No of rows of input image matrix
C=3; % No of columns of input image matrix
A = randi(255,R,C) % It will create a marix with R no of rows and C
no of colums having value b/w 1 and 255
for r=1:R
for c=1:C
if A(r,c)==255; % If pixel is 255 make it as 1
A(r,c)=1;
else
A(r,c)=0; % Otherwise 0
end
end
end
for r=1:R
for c=1:C
if A(r,c)==0; % If pixel is 0 print it
fprintf("Coordinates are: %f , %f \n ",r,c)
end
end
end
I am attaching the screenshot of code and output:
Get Answers For Free
Most questions answered within 1 hours.