Prev: Problem with refreshing figure
Next: problem
From: M Ladderman on 12 Apr 2010 07:50 OK, I checked out the output ASHAPE generates and I think I am closer to what I need now, but not there yet, I want the rectangles so I can make a polygon from them as displayed in the output image. However I do not now which to use I am trying to figure it out but help would be appreciated thanks again!! btw it seems as if ashape is working perfectly for my fish I just need to get the right perimeter data from it to use poly2mask on for my image. (a lot of thanks for this). "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hpv00b$icj$1(a)fred.mathworks.com>... > Hi, > > Stupid me I tried lower alphas, which result of course in smaller structuring disks. Stupid sorry. So I got my alpha up and get a nice segmentation image from ashape, I want to use the x and y now to get them connected in the way ashape does it. In ashape my whole fish is enclosed by connected dots (by lines). But when I use plot there is still a part missing probably because the polygon plot draws is not the same as ashape displays? > > I hope this is more or less clear what I mean. > > Cheers > > > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <aa8ee488-d330-4ad2-97a3-7807707b857c(a)h27g2000yqm.googlegroups.com>... > > Not from me - I haven't had a chance to return to looking at this. > > Maybe if you've taken my code further, you can post it and us can help > > us out (no pun intended)
From: M Ladderman on 12 Apr 2010 07:51 btw I think I am looking for the nodes? "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hpv00b$icj$1(a)fred.mathworks.com>... > Hi, > > Stupid me I tried lower alphas, which result of course in smaller structuring disks. Stupid sorry. So I got my alpha up and get a nice segmentation image from ashape, I want to use the x and y now to get them connected in the way ashape does it. In ashape my whole fish is enclosed by connected dots (by lines). But when I use plot there is still a part missing probably because the polygon plot draws is not the same as ashape displays? > > I hope this is more or less clear what I mean. > > Cheers > > > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <aa8ee488-d330-4ad2-97a3-7807707b857c(a)h27g2000yqm.googlegroups.com>... > > Not from me - I haven't had a chance to return to looking at this. > > Maybe if you've taken my code further, you can post it and us can help > > us out (no pun intended)
From: ImageAnalyst on 12 Apr 2010 08:56 Can you share your code?
From: M Ladderman on 12 Apr 2010 09:38 of course this is it, the first part is to segment the fish out of a bigger image. Then later I apply ashape, not changed from your post, excpet the alpha which should be bigger to fill gaps, then I try to get the boundary from ashape but so far unscuccesfull, x and y are not the boundaries that is a problem. I can get it from there, but I would rather used the "nodes" from ashape. That is my question, I want to get the nodes from ashape. Thanks! will keep trying. 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]); %figure, imshow(I), title('original image'); [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,:) = []; %[peakLocmin]=peakfinder(pixelCountsG,0.1*pixelCountsG(max(peakLocmax),:),-1); %rows_to_remove = any(peakLocmin >= 200, 2); %peakLocmin(rows_to_remove,:) = []; %imhist(I); %I=medfilt2(I,[5 5]); %median filtering %figure, imshow(I), title('after median filtering'); %BW = edge(I); %imshow(BW); %thresholdValue = median(peakLocmin); thresholdValuetop = max(cutoffrgb); %binaryImage = (I > thresholdValue); %figure, imshow(binaryImage), title('>'); binaryImage2 = (I < thresholdValuetop); %figure, imshow(binaryImage2), title('<'); %binaryImagefinal = (binaryImage+binaryImage2-1); %figure, imshow(binaryImagefinal), title('final'); %se = strel('disk',10); %binaryImage2=imopen(binaryImage2,se); %figure, imshow(binaryImage2), title('imopen'); BWnobord = imclearborder(binaryImage2, 4); %figure, imshow(BWnobord), title('no border'); 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); %I=green; %figure, imshow(I); 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; sizeBinary=size(FinalBinary); sizeBinary=sizeBinary(:,1); zero=zeros([sizeBinary 5],'double'); FinalBinary=[FinalBinary zero]; figure, imshow(FinalBinary); FinalBinary = imclearborder(FinalBinary, 26); 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); closeBW=im2bw(closeBW); % Get the perimeter. perimeterImage = bwperim(closeBW); subplot(2,2,2); imshow(perimeterImage, []); % Create a new axes for the alpha shapes result, % since ashape() seems to want to automatically % put results into the current axes object. subplot(2,2,3); set(gca,'YDir','reverse') % Flip upside down. [y, x] = find(perimeterImage); aslibStructure = ashape(x, y, 170); % <- select your ALPHA... subplot(2,2,4); % set(gca,'YDir','reverse') % Flip upside down. plot(aslibStructure.cen, aslibStructure.seg); axis 'equal'; ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <97544280-6cd7-467e-91b9-c0570b493f98(a)5g2000yqj.googlegroups.com>... > Can you share your code?
From: M Ladderman on 12 Apr 2010 09:52
http://picasaweb.google.com/mirresimons/Matlab#5459247749775648946 This is the picture from ASHAPE I get, so I want the coordinates of the red small rectangles. :), So I can draw a convex as in the picture, because this is perfectly fitting my fish.. woohoo :D "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hpv7nt$hfo$1(a)fred.mathworks.com>... > of course this is it, the first part is to segment the fish out of a bigger image. Then later I apply ashape, not changed from your post, excpet the alpha which should be bigger to fill gaps, then I try to get the boundary from ashape but so far unscuccesfull, x and y are not the boundaries that is a problem. I can get it from there, but I would rather used the "nodes" from ashape. That is my question, I want to get the nodes from ashape. Thanks! will keep trying. > > > 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]); > %figure, imshow(I), title('original image'); > [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,:) = []; > > %[peakLocmin]=peakfinder(pixelCountsG,0.1*pixelCountsG(max(peakLocmax),:),-1); > %rows_to_remove = any(peakLocmin >= 200, 2); > %peakLocmin(rows_to_remove,:) = []; > %imhist(I); > %I=medfilt2(I,[5 5]); %median filtering > %figure, imshow(I), title('after median filtering'); > %BW = edge(I); > %imshow(BW); > %thresholdValue = median(peakLocmin); > > thresholdValuetop = max(cutoffrgb); > > %binaryImage = (I > thresholdValue); > %figure, imshow(binaryImage), title('>'); > binaryImage2 = (I < thresholdValuetop); > %figure, imshow(binaryImage2), title('<'); > > %binaryImagefinal = (binaryImage+binaryImage2-1); > %figure, imshow(binaryImagefinal), title('final'); > > %se = strel('disk',10); > %binaryImage2=imopen(binaryImage2,se); > %figure, imshow(binaryImage2), title('imopen'); > BWnobord = imclearborder(binaryImage2, 4); > %figure, imshow(BWnobord), title('no border'); > 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); > %I=green; > %figure, imshow(I); > > 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; > sizeBinary=size(FinalBinary); > sizeBinary=sizeBinary(:,1); > zero=zeros([sizeBinary 5],'double'); > FinalBinary=[FinalBinary zero]; > figure, imshow(FinalBinary); > FinalBinary = imclearborder(FinalBinary, 26); > 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); > closeBW=im2bw(closeBW); > > > > > > % Get the perimeter. > perimeterImage = bwperim(closeBW); > subplot(2,2,2); > imshow(perimeterImage, []); > > % Create a new axes for the alpha shapes result, > % since ashape() seems to want to automatically > % put results into the current axes object. > subplot(2,2,3); > set(gca,'YDir','reverse') % Flip upside down. > > [y, x] = find(perimeterImage); > aslibStructure = ashape(x, y, 170); % <- select your ALPHA... > > subplot(2,2,4); > % set(gca,'YDir','reverse') % Flip upside down. > > plot(aslibStructure.cen, aslibStructure.seg); > axis 'equal'; > > > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <97544280-6cd7-467e-91b9-c0570b493f98(a)5g2000yqj.googlegroups.com>... > > Can you share your code? |