From: M Ladderman on
Dear all,

I need some help for ideas to solve a problem I encounter in image processing of my fish picture. Thresholding with R + G + B has resulted in reasonably good segmentation of my fish but some parts of the belly remain problamatic. I get stuck with an "open" gaps that I cannot fill reliably using imclose, because if I use too large a strel the segmentation gets worse. What I could do is do some contour fitting or so, but this is not working for me as of yet because I do not know how to approach this. I also attach my code if you have improvements there (the fish is segmented from a bigger image first and this is then segmented further using the median of the background of the bigger image).

http://picasaweb.google.com/mirresimons/Matlab#5454402906525351106

J = imread('_DSC5398.JPG');
red=J(:,:,1);
green=J(:,:,2);
blue=J(:,:,3);

medred=median(median(red));
medgreen=median(median(green));
medblue=median(median(blue));

I=(green+blue);
a=500;
b=900;
c=3600;
d=1200;
I = imcrop(I,[a b c d]);
[pixelCountsG GLs] = imhist(I);
pixelCountsG(256,:)=[];
[peakLocmax]=peakfinder(pixelCountsG,std(pixelCountsG),1);
cutoff=0.20*pixelCountsG(max(peakLocmax),:);
cutoffrgb=find(pixelCountsG<cutoff);
rows_to_remove = any(cutoffrgb >= max(peakLocmax), 2);
cutoffrgb(rows_to_remove,:) = [];

thresholdValuetop = max(cutoffrgb);
binaryImage2 = (I < thresholdValuetop);
BWnobord = imclearborder(binaryImage2, 4);
se = strel('disk',10);
BWnobord = imopen(BWnobord,se);

box=regionprops(double(BWnobord),'BoundingBox');
boxx=round(cat(1,box.BoundingBox));

length=regionprops(double(BWnobord),'MajorAxisLength');
length=round(cat(1,length.MajorAxisLength));
angle=regionprops(double(BWnobord),'Orientation');
angle=abs(round(cat(1,angle.Orientation)));

height=(1/4.5)*length+(sin(deg2rad(angle))*length);
boxx(1,4)=height;
boxx=boxx+[(a-100) (b-100) (0+100) (0+120)];

K = imcrop(J,boxx);
I=rgb2gray(K);
red=K(:,:,1);
green=K(:,:,2);
blue=K(:,:,3);

k=20;

binaryImage = (green > (medgreen+k*4));
%figure, imshow(binaryImage), title('>');
binaryImage2 = (green < (medgreen-k*1.5));
%figure, imshow(binaryImage2), title('<');
binaryImagefinalgreen = (binaryImage+binaryImage2);
%figure, imshow(binaryImagefinalgreen), title('green');


binaryImage = (blue > (medblue+k*4));
%figure, imshow(binaryImage), title('>');
binaryImage2 = (blue < (medblue-k*1.5));
%figure, imshow(binaryImage2), title('<');
binaryImagefinalblue = (binaryImage+binaryImage2);
%figure, imshow(binaryImagefinalblue), title('blue');

binaryImage = (red > (medred+k*4));
%figure, imshow(binaryImage), title('>');
binaryImage2 = (red < (medred-k*1.5));
%figure, imshow(binaryImage2), title('<');
binaryImagefinalred = binaryImage2;
%figure, imshow(binaryImagefinalred), title('red');

FinalBinary=binaryImagefinalgreen+binaryImagefinalblue+binaryImagefinalred;
figure, imshow(FinalBinary);

se = strel('disk',5);
closeBW = imclose(FinalBinary,se);
figure, imshow(closeBW);

closeBW = imfill(closeBW, 'holes');
figure, imshow(closeBW);

se = strel('disk',3);
closeBW = imopen(closeBW,se);
figure, imshow(closeBW);
From: ImageAnalyst on
I think this might be a good situation for alpha shapes. us, don't
you agree? us has uploaded an alpha shape program to the File
Exchange:
http://www.mathworks.com/matlabcentral/fileexchange/6760-ashape-a-pedestrian-alpha-shape-extractor

It's sort of like a flexible convex hull - one that can more or less
follow nooks and crannies rather than being strictly convex.
From: M Ladderman on
That looks promising, I will try and implement it. So I can set more or less how flexible the convex hull is, that is would I think I need. I had tried it a while ago this code but I did not succeed in implementing it. I will try again. It will work with binary images? Thanks!

ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <88de8fa6-05f5-46f7-8707-0a2c0f29f205(a)e7g2000yqf.googlegroups.com>...
> I think this might be a good situation for alpha shapes. us, don't
> you agree? us has uploaded an alpha shape program to the File
> Exchange:
> http://www.mathworks.com/matlabcentral/fileexchange/6760-ashape-a-pedestrian-alpha-shape-extractor
>
> It's sort of like a flexible convex hull - one that can more or less
> follow nooks and crannies rather than being strictly convex.
From: M Ladderman on
Stupid question maybe but I cannot remember how to get x,y from a binary image (so two vectors that describe where the 1 of the binary image are at), to use that for the input in Ashape.

"M Ladderman" <mirresimons(a)gmail.com> wrote in message <hot13j$fm7$1(a)fred.mathworks.com>...
> That looks promising, I will try and implement it. So I can set more or less how flexible the convex hull is, that is would I think I need. I had tried it a while ago this code but I did not succeed in implementing it. I will try again. It will work with binary images? Thanks!
>
> ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <88de8fa6-05f5-46f7-8707-0a2c0f29f205(a)e7g2000yqf.googlegroups.com>...
> > I think this might be a good situation for alpha shapes. us, don't
> > you agree? us has uploaded an alpha shape program to the File
> > Exchange:
> > http://www.mathworks.com/matlabcentral/fileexchange/6760-ashape-a-pedestrian-alpha-shape-extractor
> >
> > It's sort of like a flexible convex hull - one that can more or less
> > follow nooks and crannies rather than being strictly convex.
From: ImageAnalyst on
You can use bwboundaries on the binary image to get the boundary
coordinates. I haven't used us's alpha shape program yet, but
generally there is a parameter (maybe more) that basically say how
tightly the estimated shape "hugs" the actual shape. Here are some
more references for alpha shapes:
http://biogeometry.duke.edu/software/alphashapes/index.html
http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html
http://www.cgal.org/Manual/last/doc_html/cgal_manual/packages.html#Part:ConvexHullAlgorithms

You might also try a restricted convex hull. It's like a convex hull
but it doesn't search ALL the other points, it only searches nearby
points so it's convex only in certain regions and is able to follow
into the "bays" somewhat. It has a parameter that says how many
nearby points to consider and this controls how closely it hugs the
points.
 |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: Problem with refreshing figure
Next: problem