Odd Outcome From imerode and bwlabel

1 回表示 (過去 30 日間)
ssklios Sklios
ssklios Sklios 2011 年 10 月 17 日
Hello,
I am trying to program a shape placement algorithm using image processing in Matlab.
The algorithm should place images of shapes on a larger background image in a way that minimizes the wasted background. I am using imerode to erode the current background image with the bounding box of the shape to be placed as the structuring element. Thus, imerode should return an image with 1's everywhere where the origin of the structuring element can be placed so that it is entirely contained within the background image. Imerode does this correctly. However, when I use bwlabel on the image returned from erosion for further processing, an image of the structuring element appears in the bottom left corner. I don't understand why this is happening. I'm sure it would help to see the images that I am refering to but I don't think pictures can be attached to this question. Can anyone explain please? Any help would be greatly appreciated. Thank you.
  2 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 10 月 17 日
Use a free image hosting website and give us the link. Also, post the code and use formatting so we can see what MATLAB is _actually_ doing.
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Sean de Wolski
Sean de Wolski 2011 年 10 月 17 日
Welcome to MATLAB Answers!

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

回答 (2 件)

ssklios Sklios
ssklios Sklios 2011 年 10 月 24 日
Thank you so much for responding. Here are examples of the images in question:
Notice the strange image in the bottom right of the bwlabel image. I will upload some of the code shortly. Thanks again!

ssklios Sklios
ssklios Sklios 2011 年 10 月 29 日
Here is the part of my code that has to do with imerode. currentpart is an image of a shape to be placed and current scene is the background that the shape has to be placed on. I first rotate the shape image to align with the background. Then make the structuring element the image of the bounding box of the shape. Then erode the structuring element into the current scene.
%rotate
partrot=RotObject(currentpart,angles(b));
partrot=bwlabel(partrot);
partstats=regionprops(partrot,'BoundingBox','Image');
%Extend current scene
bb=minBoundingBox(partrot);
LH=lengthheight(bb);
L=LH(1);
H=LH(2);
currentscene(1,1)=currentscene(1,1)+H*cos(backanglerads-pi/2)+L*cos(backanglerads);
currentscene(1,2)=currentscene(1,2)+H*sin(backanglerads-pi/2)+L*sin(backanglerads);
currentscene(2,1)=currentscene(2,1)+H*cos(backanglerads-pi/2);
currentscene(2,2)=currentscene(2,2)+H*sin(backanglerads-pi/2);
currentscene(4,1)=currentscene(4,1)+L*cos(backanglerads);
currentscene(4,2)=currentscene(4,2)+L*sin(backanglerads);
[r c]=size(fullscene);
M = poly2mask(currentscene(:,1), currentscene(:,2), r, c);
currentscene=immultiply(M,fullscene);
%Make structuring element
S=strel(partstats.Image);
strelcent=floor((size(partstats.Image)+1)/2);
boxcent=[partstats.BoundingBox(2)+strelcent(1) partstats.BoundingBox(1)+strelcent(2)];
%make placement
pos=imerode(currentscene,S);
posL= bwlabel(pos')';

カテゴリ

Help Center および File ExchangeDisplay and Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by