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

조회 수: 9 (최근 30일)
Loren99
Loren99 2022년 6월 9일
편집: Loren99 2022년 6월 15일
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
Loren99
Loren99 2022년 6월 9일
편집: Loren99 2022년 6월 10일
@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)
Loren99
Loren99 2022년 6월 9일
편집: Loren99 2022년 6월 9일
@Image Analyst I have to check first all the initial points x1,y1 ; then all the final points x2,y2

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2022년 6월 9일
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
Loren99
Loren99 2022년 6월 9일
@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?
Image Analyst
Image Analyst 2022년 6월 10일
  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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by