Transform boundary image to 2d plan coordinates

Hi, I need to transform some images (that represent different objects boundary line) to a curve on matlab. The images are like this
what I need to do is to "place" this curve and the area inside it in a 2d space in order to make an if cicle: if I am inside this area I have some requirements, if I am outside I have different requirements (an example would be a gps use: if I am inside an area defined by this curve and so inside some longitude and latitude limits I have three restaurants, if I am outside I have no restaurant). Can somebody help?

 Akzeptierte Antwort

Image Analyst
Image Analyst am 18 Nov. 2014

1 Stimme

What is an "if cicle"? If you have the x,y coordinates of the boundary/perimeter/curve, then you can use inpolygon() to determine if a point is inside or not. I don't know what else to say since I don't know what it means "to place this curve and the area inside it in a 2D space" nor do I know what an "if cicle" is. Isn't the curve ALREADY in a 2D space? It's in a plane isn't it?

10 Kommentare

matteo
matteo am 18 Nov. 2014
Bearbeitet: matteo am 19 Nov. 2014
I think the example I wrote was good enough to explain. I have this image I posted but it's a png file. I have to upload this on matlab and define the blue curve in coordinates (like a matrix X,Y with all the blue pixels). Then I think I can use inpolygon()
If cicle means that I have to write a code like if my position (X,Y) is inside the area defined by the blue curve do something else do something else.
can this explanation work?
Well, cicle is not an English word, at least not where I'm from. Perhaps you mean "a while loop" or "a for loop". I don't know what you're starting with. Are you starting with a white image with a blue line on it, or are you starting with an array of (x,y) coordinates? What does "upload this on matlab" mean? Do you mean "read in the image"? If so, you can simply use imread(). Then you can find the blue coordinates and just scan the image from top to bottom and use inpolygon() to determine if each pixel is inside or not and take appropriate action based on the result. What would that action be? Do you just want to place N restaurants at random locations inside the blue curve? Please elaborate so I can help you.
matteo
matteo am 19 Nov. 2014
Bearbeitet: matteo am 19 Nov. 2014
Thank you so much. I know I've not explained my self very well (I'm not english) but you gave me the perfect advice (inpolygon). I'm working on my master thesis in space engineer and this I ask is just a small part of a bigger software very diffult to explain. What I've done is:
1)read the image I posted with imread
2)use points2contour to re-order image's points
3)use inpolygon to determine if one point is in or out the area defined by the curve on the image I posted .
The use of points2contour is needed because with a casual distribution there are errors in the inpolygon function
Do you just need a mask that's true inside the blue line and false (black) outside? If so, that's easy. Just take the red channel, threshold, and call imfill().
matteo
matteo am 19 Nov. 2014
Bearbeitet: matteo am 19 Nov. 2014
more or less this is just what I need to do thanks, but in my case inpolygon works better
But you have a problem in that your contour is not closed so inpolygon won't work. I know it's not closed because I did it my way and it didn't fill it. When I dilated the perimeter, then it closed it up. But then you might as well use imfill() in a single line of code then rather than a nested for loop calling inpolygon.
The m-file is attached below.
matteo
matteo am 20 Nov. 2014
Hi thanks for this, maybe I'll have some other question later (I keep working on my thesis so I can't know by now if it's going to work well for my study)
matteo
matteo am 21 Nov. 2014
Bearbeitet: matteo am 21 Nov. 2014
Hi, I've gone forward in my thesis:
I transformed that area in an area over a spherical surface (earth surface) now I have a point above this surface (some km above). I need to define the 3d cone that has for vertex the point and base the area. Then I have to define if some other points I'm going to enter in this model are inside or outside this "cone".
OK. Good luck. Thanks for Accepting the answer. I don't really know how to do your latest task but I think Roger Stafford probably does. I suggest you post it as a brand new question. And detail exactly what "define this 3d cone" means, mathematically.
matteo
matteo am 21 Nov. 2014
Thanks again for your help, you've really saved mylife so far.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 18 Nov. 2014

Kommentiert:

am 21 Nov. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by