How to find the x and y coordinates of points inside a binary image M?
Mostra commenti meno recenti
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
Matt J
il 9 Giu 2022
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?
Image Analyst
il 9 Giu 2022
Modificato: Image Analyst
il 9 Giu 2022
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')
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
Risposte (1)
Image Analyst
il 9 Giu 2022
0 voti
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
Loren99
il 9 Giu 2022
Image Analyst
il 10 Giu 2022
- I did not say that. I said "Write all the endpoints".
- You can do binaryImage(round(y2(k)), round(x2(k))) = true; Iterate over all k and also do the x1 and y2 arrays.
- 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.
Categorie
Scopri di più su Region and Image Properties in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
