Gridded An Irregular Area With Matlab

Dear All..
I have a problem with my final project about matlab. Those problem are : 1. How can i divide an irregular area into a small blocks (grid) ? Please, can anyone give me a code? Before, i built the irregular area by connected point to point coordinates of the X an Y axis. 2. That code can work when we input a size of the grid, so it's automatically generated by the size that we given. 3. Everyone, please help me. The date of my deadline already close enough.
here, i attach a map figure of irregular area that i mean above. i'm very thankful for your help.
sincerely, Allice Ellisa

 Accepted Answer

Image Analyst
Image Analyst on 31 May 2014
Edited: Image Analyst on 31 May 2014
Please plot your original image of the irregular regions, without the spots and axes, so we can try some things.
If you simply want gridlines overlaid on the image, you can do
grid on;
What do you want to do when you're near the edge of an irregular region and the 8 by 8 window would go outside the region? Do you just want a list of those pixels that do lie inside the region?

25 Comments

the grid that i mean is a virtual grid, that cover all the surface of the region. actually i'm estimating the unmeasured value on that certain part of the region by ordinary kriging method. and the problem is, i don't have any grid inside the map. because ordinary kriging method cannot work without any grid. so, i cannot use simply "grid on" to the map.
yes, absolutely right. i just want a list of those pixels that do lie inside the region. and that grid or pixel can be automatically generate by my entered size. for example, when i input "grid 1", the map will automatically covered by grids that has a size 1x1 for each grid.
below, the map without any center. I'm so sorry for my badly english.
Try using griddedInterpolant() to get a regular grid, that is, a solid 2D matrix with values at every location.
then how do i know, that the grid is in the region? is there any filter of the map's coordinate, which separate inner and outer map? thanks before :)
I don't know the form of the data that you're starting with. What is it? Is it an image (peta.png) with blue lines and dots like you showed originally? Is it a list of the (x,y) coordinates of the blue lines? Is it something else? I have no idea. I asked you to post your image or whatever, but you're not doing it for some reason.
excuse me, i have posted the image that you requested before, i don't know, why it was gone, i'm sorry. let me to post it one again yes, the map is consist of (x,y) coordinates, and the main problem is, how can i divide the area into small pieces of grid, upon the boundary that plot. and the number of pieces, based on the size grid when i give it.
i'm so sorry of my fault before, i really need your help, Sir
Image Analyst
Image Analyst on 31 May 2014
Edited: Image Analyst on 31 May 2014
I asked "Please plot your original image of the irregular regions, without the spots and axes", so why do you have axes there? It will take code to get rid of them. What are you saving? The image, or the figure? Why can't I have just the image with the blue lines? Why can't you give that to us? Why do we have to have black axes with it?
And what does this have to do with MATLAB Coder (which you tagged it with). Coder translates MATLAB code into C. Do you want to do that? If so, why?
Your blue lines are not even connected so that they don't enclose the regions completely. Again, I don't know what data you're starting with and exactly what you want when you say you want to "divide the area into small pieces of grid, upon the boundary that plot." Are you starting with a binary image? A list of boundary coordinates? What? And what if you don't have a full square grid, like near the boundaries? Do you count that as a full box when you're counting the number of boxes that fit into a region? And do you know that this number will change depending on exactly how the grid is aligned with your regions? Move the grid over 1, 2, 3, and 4 pixels and you may get an entirely different count for each region because how the grid lines up with the region will be different. Do you care about that? I'm willing to help but you have to give me something to work with and some precise instructions of what you want as an output.
OK, this is what I've been able to do with the very limited information you have given me. See attached code test.m that will produce this image, and measure all the areas of all the regions.
Ellisa Dewi
Ellisa Dewi on 1 Jun 2014
Edited: Ellisa Dewi on 1 Jun 2014
I'm so sorry of my poor in English, Sir. 1. I got that map, from connected point to point in coordinate (x,y). Actually I have a hardcopy map, and i confused, how i change it into softcopy. So i manually measure, point by point which contain coordinate (x,y) then wrote the result in matlab, and connected by plot(x,y)
2. In my final project, i have to calculate the estimation value of all the surface of that region. So that, i have to create grids inside the region. That grid, automatically generate by the size based on my input. So, if I want more detail estimation value as the result, i'll input small size of grid. For example " Grid Size = 0.5 ", then it automatically create a grid inside the region within 0.5x0.5 size for each block. When i give 0.1 for the size, it will create a grid in 0.1x0.1 size, and of course the number of the grids inside are greater, than 0.5x0.5 in size.
3. Here i attach the image's scan result of the original hardcopy map
I'm so sorry of my bad English, Sir. actually i understand what you mean, but i cannot deliver my answer well to you.
and, here the grid's mean that i mean in irregular region
above
Why not just make the grid as small as possible? That would be one pixel. That would give you the most accurate area possible. I don't see the point of starting with a large grid and making it smaller. Just start off with the smallest to begin with. So, then your task is to get rid of the black lines and text, and red line. Let me know if you need help with that. Once you do that call regionprops to get the areas.
so, it means we will gridded the region above just from the original map when it's empty without any texts and lines, Sir? But I need the center coordinates from each grid, what can i get it, Sir?
i mean i want to colour the map using contour gradation color (inside the map only)... what should i do cause i ever try but all of the x axis and y axis being colored too
I don't know the reason for the grid/boxes. Why? Just as an exercise to see how the area increases and converges as the boxes get smaller? What's the point? Why not just start with a box size of one pixel? Why do you need the centroids of the boxes anyway? It's totally arbitrary and changes for a given box size depending on where the box edges lie. So why bother to give centroids? It's useless and arbitrary.
Ellisa Dewi
Ellisa Dewi on 1 Jun 2014
Edited: Ellisa Dewi on 1 Jun 2014
My main program in final project need this calculation from center of the grids so that now i'm confused when i have to make a grid, then find the center. if the region is rectangle, maybe it doesn't matter, but this is an irregular region. so i don't know, what's the code to make it work properly
this is the map after i delete the text and black line, Sir
But that looks like the outer edge of the whole map. What happened to the individual countries? Do you not care about those? If not, it's much easier - just fill the shape and use 2 nested for loops to determine if the current point is within the shape. The centroid of the box is obviously at the mid point between its vertical edges and horizontal edges.
[rows, columns] = size(binaryImage);
insideBox = 0; % Count of # of boxes inside shape.
binaryImage = imfill(binaryImage, 'holes');
for col = 1 : boxSize : columns
for row = 1 : boxSize : rows
if binaryImage(row, col)
insideBox = insideBox + 1;
end
end
end
That's untested code, so you'll have to debug it.
actually for each individual country should be considered, but i will think it after the simple one is done. hmm, the picture above was in a jpg format, how can i convert it into matlab? i'm sorry Sir, i really newbie here, and the final project charges me to solve this difficult one. Thanks before
The hard part is that there's a bunch of noise in the colors, and there is a bunch of text. I tried for about half an hour but was only somewhat successful in getting good images. Can you get the outlines of the countries? How did you get the blue outlines? Do you have a version of the map without black annotations on it?
actually we shouldn't notice for the texts and colors, because the most important problem is how to get the color's gradation of the estimation value within "contourf" (or i can say, where there is a greater estimation value in some place, the color will be brighter than another). And the prosedure of estimation will work, when i get the center of each grid for all the surface of the region.
i got the blue outlines with connected point by point which calculated manually, and i connected them by command "plot(x,y)" in matlab. maybe it was wrong Sir, and we shouldn't notice about that. the problem that i confused of is 1. how can i enter the image of the .jpg map's image above into matlab? So that i can test your code. hmm i think that code is to diferentiate black and white first, right? so we can continue the next process? 2. when i can test that code, and i can diferentiate the black's boundary with the white's inside, how can i split it into the smallest grid, to get the most accurate estimation value, Sir?
by the way, i don't have a version of the map without black annotation, Sir.
When you're placing boxes around your image, how are you going to know which of the 12 regions it's over? Can we assume that we'll start with your blue lined image and that all regions will be completely enclosed (no gaps in the blue lines).
yes of course we can. i think it doesn't matter anymore about where we will start and end with. because, the important thing of it is we can cover all of the region's surface with the boxes (within certainly size, eg : 0.05x0.05). i'm really confuse with this problem, Sir. and don't know, how to solve it.
Sir, are you still here? Would you like to help me, Sir?

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!