How to vertically and horizontally scan an image to store a coordinates (positions) of the elements having values other than 255.
8 次查看(过去 30 天)
显示 更早的评论
I want to identify or locate the coordinates of the multi-colored blob present on the white background i.e. (255) as shown in the figure.
For this purpose, I want to scan the attached image image both horizontally and vertically. Scanning should stop and display the coordinates where it finds the pixels value other than 0. The same procedure should be continued for whole image to identify all the coordinates having values other than 255.
I have tried to code it but unable to do so. Code is attached for your reference.
I=imread(Image2); % Read input image
[height, width, plane] = size(I);
Coordinates = zeros(height,width);
for i=1:height
for j=1:width
x=i;
y=j;
if I(i,j)~=0
Coordinate(x,y)=I(i,j)
end
end
end
I have attached the two images for your reference. Image1 is manually described multi-colored blob with rectangle. And Image2 is the originlal image.
Any help is much appreciated. Thank you!!!
0 个评论
回答(2 个)
Joseph Cheng
2021-6-4
do you need to "scan" in a for loop or are you just looking for the positions of the colors? if you don't need to scan in a for loop the function find() will get the values for you
img = imread('pears.png');
bwimg = rgb2gray(img);
x = linspace(-1,1,size(img,2));
y = linspace(-1,1,size(img,1));
[X,Y]=meshgrid(x,y);
bwimg(sqrt(X.^2+Y.^2)>=.1)=255;
figure,image(bwimg),colormap gray
[r,c,V]=find(bwimg~=255);
hold on
k = boundary(c,r); %just for easier plotting to show points collected
plot(c(k),r(k),'r')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!