siavashk / pycpd

Pure Numpy Implementation of the Coherent Point Drift Algorithm
MIT License
513 stars 115 forks source link

convert 2D image into the point set representation #39

Closed cheng043 closed 4 years ago

cheng043 commented 4 years ago

Is there a way to convert a 2D image into the point set representation as used in the code ?

gattia commented 4 years ago

More information is needed to answer your question. What is the image? Are there unique values in the image that you could assign to be the points?

If you have a segmentation image, and each pixel of the image is assigned to be the border of a tissue of interest, then you could easily extract those pixel locations from the image and use them in this algorithm. For example:

import numpy as np
y = np.asarray(np.where(x==1))

The above assumes that you have an image x, and you want to make all of the pixels valued 1 to be your points.

However, if you have a full segmentation (not just the border) you will need to find the pixels on the border of the segmentation. You can look up something called marching cubes or marching squares - there are many implementations.

If you have a raw image. Then, you will either need to segment the image and do the appropriate steps as described above. Or, you may be able to threshold the image in some way. E.g., you could identify that the border pixels of the object you are interested in are all within a specified range - so, say you have an image and you identify that all of the pixels on the border of the object are between 5-10 then you could use this twist on the above code:

import numpy as np
y = np.asarray(np.where(((x>5) and (x<10))))

The above would get the x,y coordinates of all pixels in the image x that have a value between 5 and 10.

Again, these are just some general ideas. More detailed information about your example are needed to provide any specific information/insights.

cheng043 commented 4 years ago

Got it thanks.

gattia commented 4 years ago

Did this work out for you? Which suggestion did?

If everything is resolved, is it alright if we close this issue?

siavashk commented 4 years ago

Thank you @gattia for developing low-rank and other quality-of-life improvements. I have merged your pull requests with the development branch. I think when we merge development into master we should bump the version to 2.1.0.

That being said, I also think that our current examples might be insufficient to help new users with pycpd. When I have more time, I will go through the issues and see if I can create a better set of examples.

gattia commented 4 years ago

Sounds good. I think we can close this one.

Let me know what you’re thinking for examples. I’m happy to contribute as best I can. Either making new ones or code review.