How to vertically and horizontally scan an image to store a coordinates (positions) of the elements having values other than 255.

8 visualizzazioni (ultimi 30 giorni)
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!!!

Risposte (2)

Joseph Cheng
Joseph Cheng il 4 Giu 2021
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')
  1 Commento
kanika bhalla
kanika bhalla il 4 Giu 2021
Thank you so much @Joseph Chengfor your answer. Actually i want to scan so as to get the positions of the colored part with row and column number. So that later I will acess those rows and column easily.
I have also tried the code given by you but it is giving error. Error is described below:
Error using linspace
Too many input arguments.
Thank you for your time.

Accedi per commentare.


kanika bhalla
kanika bhalla il 5 Giu 2021
Sir @Walter Roberson, Could you please help me reagrding my query.

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by