Plot binary image with all coordinates of points

I have a matrix with 2 rows:
First is x-coordinate
Second is y-coordinate
How can i plot a binary image with all coordinates of points in that matrix

3 comentarios

KSSV
KSSV el 12 de Oct. de 2017
What data you have as pixel or z data?
Guillaume
Guillaume el 12 de Oct. de 2017
Editada: Guillaume el 12 de Oct. de 2017
Nguyen Hung comment moved here (Please use comments, not answers):
Actually, I plot a contour from a blood sample and receive a contour matrix. So, my coordinates don't have natural spacing; I want to count cell by counting closed loop in contour image. Is there any way to do so?
I would recommend a different approach for that.
  1. quantize the readings according to the contour levels you want.
  2. replace each array entry by the bin number of the quantized level
  3. now use regionprops to figure out all of the distinct regions. If you only need to know how many there are, then ask for any simple property, but then look at the size of the returned structure to see how many regions there were.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Oct. de 2017
If the coordinates are positive integers, then
binary_image = full( sparse( YourMatrix(1, :), YourMatrix(2, :), true ) );

8 comentarios

Nguyen Hung
Nguyen Hung el 12 de Oct. de 2017
the coordinates is all positive but not integers. How can i do?
What result would you like in that case?
Is there a natural spacing, such as if the coordinates might end in .0 or .25 or .5 or .75 giving a natural spacing of 1/4 unit? If there is then you can divide the coordinates by the spacing in order to get integers that can be processed like above.
If there is no natural spacing, do you want to quantize the coordinates, such as if you want to treat anything beween 0.15 and 0.20 as belonging in the slot for .15? Thus getting you an artificial spacing that you can use to determine which pixel to light?
If there is no natural spacing and you do not want to quantize, do you want to do something like have each coordinate pair act as a circle of constant radius around it, and any pixel which in total is more than half covered by touching or overlapping circles is to be treated as lit?
If there is no natural spacing, do you want to light pixels based upon density of points? Perhaps with a denser block lighting a larger block?
... and so on. You need to tell us how you want to determine which pixel(s) are lit given your list of coordinates.
Nguyen Hung
Nguyen Hung el 11 de Nov. de 2017
I have maxtrix p is 2x21014 double which have 1st row is the x-coordinates, 2nd row is y-coordinate correspoding.
I want to plot an image size 331x504 with all 1s have coordinates in p.
My coordinates in p don't have any rules and i want to quantize to 5% as between 0.5 and 0 to 0
Image Analyst
Image Analyst el 11 de Nov. de 2017
What does it mean to "plot" an image? Do you mean "display" an image, like with imshow()? Or do you want to plot the x coordinates in a line plot or bar chart or something?
x = p(:,1);
y = p(:,2);
minx = min(x);
maxx = max(x);
miny = min(y);
maxy = max(y);
target_rows = 331;
target_cols = 504;
xsteps = linspace(minx, maxx, target_cols+1);
xsteps(end) = inf;
ysteps = linspace(miny, maxy, target_rows+1);
ysteps(end) = inf;
[~, xbin] = histc(x, xsteps);
[~, ybin] = histc(y, ysteps);
dimg = accumarray([ybin, xbin], 1, [target_rows, target_cols]);
bwimg = dimg > 0;
subplot(1,2,1); imshow(dimg); title('density')
subplot(1,2,2); imshow(bwimg); title('occupancy')
Nguyen Hung
Nguyen Hung el 12 de Nov. de 2017
Thank you very much!. It's exactly what i need.
Hélène MACHER
Hélène MACHER el 31 de Mayo de 2019
Editada: Hélène MACHER el 31 de Mayo de 2019
Hello,
Thank you very much for your answer, it's much more faster than whith for loops.
I'm working on a filtering algorithm for point clouds. I create a binary image from a point cloud and I clean this image thanks to several functions available in Matlab.
Then, I would like to go back to the point cloud in other words I would like to find the points corresponding to the white pixels. I manage to do this with for loops but it's quite long. Any idea to do it faster?
Hélène
Along with your binary image create a 2d array in which each value is 0 if the binary is unoccupied, and is the linear index of the original in the point cloud for occupied. Do the processing on the binary image. Then multiply the result binary image by the coordinate array. The nonzero values left are the indices of the original point cloud.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 12 de Oct. de 2017

Comentada:

el 31 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by