Identify which color zone a x - y point is in
Show older comments
Hi
I have this image where I have identified the different zones using RBG.
After that I stored the different colorareas from zone 1-9.
Ive placed the image inside a x - y axis.
xlim([0 10]) & ylim([0 10])
Now I have a point value of: point = ([5 2]);
This when i plot this, it is inside the "blue" area stored as zone_6.
The RGB color is: ([0 0 204])
How can I make a code that, when I plot a value it gives me which zone it is in?
Ive placed my code in a zip file, so you don't have to identify the different zones, Ive already done that. But I cant solve how to find the zones from a x-y coordinate.

2 Comments
Two quick comments about your code:
- Using numbered variables is horrible code™. Best not to do it or it is a near certainty you'll regret it later.
- You pass nine (numbered) variables to your function and proceed to immediately delete everything. What's the point of that? To add insult to injury, you also hard-code them after having destroyed them.
I don't have the Image Processing Toolbox so it is tricky for me to help you further.
Stephen23
on 6 Sep 2017
"After that I stored the different colorareas from zone 1-9."
As everyone has already told you, creating and accessing numbered variables is invariably a bad way to write code. Read this to know why:
Accepted Answer
More Answers (2)
Floriane Madeleine Schreiber
on 5 Sep 2017
0 votes
Hello Mikkel,
I think, the first thing to do, is to find the value in your matrix corresponding to your coordinates. For example : x = 5. in your matrix the length of x is 2000. You use a cross multiplication, and you find the index_x = 1000. for y=2, you do the same, but now you find a decimal number index_y=337.8000. You cab round it (index_y=338) or look the value before (index_y=337) and after (index_y=338); Now, i have the two index that i can put in my matrix img; like : a=img(338,1000,:);
and a will be :
a(:,:,1) = 0 a(:,:,2) = 0 a(:,:,3) = 204
so you have your RGB code for your x and y coordinates.
now, you can add some if-condition with the number like :
b=[a(:,:,1) a(:,:,2) a(:,:,3)];
if b(1)==0 && b(2)==0 && b(3)==204 sprintf('it is blue and it is in the zone_6') zone='zone_6'; end
with your different RGB codes !
Hope it helps you and answers at your question. Don't hesitate to ask me if it is not clear or not complete.
2 Comments
Mikkel Ibsen
on 6 Sep 2017
@Floriane,
Please use the formatting tools to make your post more readable. See the help link that you can click each time you write/edit a comment/answer.
Kevin Krüger
on 6 Sep 2017
0 votes
If I understand this correctly, you already specified each Zone by the points which belongs to it. Now to solve your Problem, you have to go the other direction. With a given Point you can determine the corresponding color. And with the color you can determine the corresponding Zone. I think this is what Floriane is doing.
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!