How to find the x and y coordinates of points inside a binary image M?

Hi everyone! I need a help with a code. On one hand, I have a binary image M (logical); on the other hand, I have vrx (2x658) and vry (2x658) where the first row of vrx is the x coordinate of the initial point of a line, the second row of vrx is the x coordinate of the final point of a line. The same reasoning is valid for vry but it is the y_coordinate.
Starting from the initial points of a line (so the elements vrx(1,:) and vry(1,:)), the code has to check, in correspondence of every single point of coordinates vrx and vry, if the binary image M in that specific point has value 1 or 0. If the value of M is 1, then I have to remove that point from the total vector. If the value of M is 0, that point can stay in the total vector. The same procedure must be done for the final points of a line (so the elements vrx(2,:) and vry(2,:); at the end I have to plot the new vectors vrx and vry obtained, after this check.
My problem is that I don't know how to make this correspondence between the vrx and vry coordinates of the current point I am analyzing and the value that the binary Image M assumes at that specific point.

4 Commenti

the code has to check, in correspondence of every single point of coordinates vrx and vry, if the binary image M in that specific point has value 1 or 0.
The vrx,vry coordinates in your attached input data are not integer coordinates. This means they never truly coincide with any M(i,j). Are the vrx,vry supposed to be rounded in some way to a nearby pixel location?
So you have 658 line segments. Do you want to check the points in between the end points, or only the exact end points themselves?
s = load('untitled.mat')
s = struct with fields:
M: [241×321 logical] vrx: [2×658 double] vry: [2×658 double]
imshow(s.M)
vrx = s.vrx;
vry = s.vry;
hold on
for k = 1 : length(vrx)
x1 = vrx(1, k);
y1 = vry(1, k);
x2 = vrx(2, k);
y2 = vry(2, k);
plot([x1, x2], [y1, y2], 'r.-', 'MarkerSize', 7)
end
@Matt J yes, I was thinking about the fact that for example vrx and vry coordinates like (149.5 ; 158,5) could be rounded to the pixel coordinates (149;158)
@Image Analyst I have to check first all the initial points x1,y1 ; then all the final points x2,y2

Accedi per commentare.

Risposte (1)

Write all the endpoints to a binary image. Then use imreconstruct. I bet you can figure it out, but if you can't, write back for help.

2 Commenti

@Image Analyst sorry but I don't understand how this answer is linked to my question. Then:
1) Why I have to consider only the endpoints (x2,y2) and not also (x1,y1)?
2) How can i write the endpoints to a binary image?
3) Why I have to use imreconstruct?
  1. I did not say that. I said "Write all the endpoints".
  2. You can do binaryImage(round(y2(k)), round(x2(k))) = true; Iterate over all k and also do the x1 and y2 arrays.
  3. imreconstruct will tell you what regions/blobs in the mask image also contain any pixels from the marker image. So if your mask image is your M array, and your marker image is the one you created in #2 above, you'll know which blobs the xy points are in and then you can erase those from M.

Accedi per commentare.

Prodotti

Release

R2021b

Richiesto:

il 9 Giu 2022

Modificato:

il 15 Giu 2022

Community Treasure Hunt

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

Start Hunting!

Translated by