Dividing and filling an irregularly shaped image

3 ビュー (過去 30 日間)
Pedro Serra
Pedro Serra 2011 年 3 月 28 日
Dear all,
I'm struggling with an issue regarding the above title. Here's the thing:
I have an image (a foot) from which I have recovered the edges (the image is now only composed of the outlines of the foot);
The image is converted to a matrix.
My objective is to divide the image into a number of regions, specified by the user, and make each region color dependent on a value recovered by a sensor. In order to due that I've been thinking of:
  1. Drawing a grid;
  2. Find the points where the grid and the image superimpose;
  3. Create a polygon delimited by those points;
  4. Divide the area of the polygon in the number of regions specified;
  5. Color the region with the value from the sensor.
I'm stuck at 3.
I can't think of another option to do this. I've considered using 'fill', 'roifill', 'blockproc'. I've had success with none. Is there any advice you could give me on how to approach the issue? Even a suggestion on what function to use would be nice.
Regards, Pedro

回答 (2 件)

Sean de Wolski
Sean de Wolski 2011 年 3 月 29 日
Of course it can!
Ms = zeros(256,256,3,'uint8'); %preallocate
Ms(:,:,1) = poly2mask([95 106 118],[48 66 45],256,256); %3 random triangles
Ms(:,:,2) = poly2mask([35 26 78],[78 26 35],256,256);
Ms(:,:,3) = poly2mask([127 159 180],[211 205 231],256,256);
L3d = bsxfun(@times,Ms,uint8(bsxfun(@times,permute((1:3).',[3 2 1]),ones(1,256,3)))); %make label
L = max(L3d,[],3); %each object will be the biggest label
%view
imshow(label2rgb(L))
%Now to do any math, i.e. your point 5:
New_Image = zeros(256,256);
New_Image(L==3) = some_thing; %will make the assignment to a new color
This can be expanded upon, but you'll need to provide us with more details. Good Luck!

Sean de Wolski
Sean de Wolski 2011 年 3 月 28 日
how about:
doc poly2mask
? Create a mask for each reason; then augment them together as a label matrix (i.e background = 0; monotonically increasing integers for each region) then you can do all sorts of automated fun stuff with that!
  1 件のコメント
Pedro Serra
Pedro Serra 2011 年 3 月 29 日
@Sean, thank you for the suggestion.
I looked up the info on poly2mask. According to that, I got the idea that I can't control its color...In that way, I would have a problem further along the path (point 5).

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by