MATLAB Answers

Assigning property/value to image color, Oklahoma state

1 view (last 30 days)
djr
djr on 28 Mar 2015
Commented: djr on 30 Mar 2015
Hello,
I have a very simple image (attached) that has white background and several filled circles of different colors. I am interested in the part of the image that is inside the line boundary (approximate boundaries for Oklahoma state). How can create matrices/grids that will have different numbers based on the color of the circles. For instance, the matrix/grid for red circles (color) should have value 5 for red color and 0 for whatever is not red; green should have 3 inside and 0 outside, etc.
Thanks, DjR

  3 Comments

Image Analyst
Image Analyst on 28 Mar 2015
Attach your original image and what you want your output indexed image to look like. And why do I need a grid?
djr
djr on 28 Mar 2015
Sorry for not attaching the image. It's attached now.
I'm analyzing tornado footprints for Oklahoma. I need exposure for different areas within the state. Cities have high exposure, uninhabited desert small, etc. So my circles represents different exposures. Based on this, my idea is to create multidimensional array that will have lon/lat grid as the first dimension and exposure data based on the color of the circles as the second dimension. So, let's say exposure for white background is 0, 1 for green, 2 for red, etc. This image is very, very simplified, but it can be more complex and shapes don't have to be circles. Also, lon/lat can be one dimensional array because I can say that Lon = 22.54 and Lat = 31.14 is 2254.3114 and so on for any lon/lat combination.
So at the end when I overlap the tornado footprint over that matrix, I can see what the exposure was and finally estimate the damage associated with the event. I think that associating the exposure with a color can be good because the code gets generic.
If I figure out (with your help) how to create this 2 dimensional array reading the image that I would be able to add more layers if necessary (e.g. vulnerability, type of houses etc.). Hope this explanation helped.

Sign in to comment.

Accepted Answer

Chad Greene
Chad Greene on 30 Mar 2015
Assuming you have data in x and y coordinates (switch x and y with lon and lat, if you're using geocoordinates), start by preallocating some empty matrix the size of your full x,y grid:
MyMap = zeros(mapheightpx,mapwidthpx);
where mapheightpx and mapwidthpx are the size of the categorical data map you'll be creating. Set red circle areas to 5 and green to 3:
red = inpolygon(gridx,gridy,redcircleoutlinex,redcircleoutliney);
MyMap(red) = 5;
green = inpolygon(gridx,gridy,greencircleoutlinex,greencircleoutliney);
MyMap(green) = 3;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by