Prev: Problem with refreshing figure
Next: problem
From: M Ladderman on 19 Apr 2010 08:19 Hi all, I am still stuck... I can plot using line() or plot() the perimeter of my ROI created using ASHAPE. But now I want to convert this to a binary mask... How to proceed?? Please help I can't seem to find how to do this. Cheers. "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hqblnj$fvb$1(a)fred.mathworks.com>... > Hi all, > > I have tried to figure it out myself but with little luck. The line function returns a handle for each line which is the length or so? But no angles, so I do not know how to use this to convert this to a binary or plot it onto my earlier binary image. The polygon option is not the way to go I guess because the segmentation seems to be worse. > > L > > "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hq7vdq$a32$1(a)fred.mathworks.com>... > > I guess this is because the polygon drawn, draws some lines that are not the shortest lines to connect the nodes as are drawn when you use line as suggested by us. But from this line part it must be possible to mask this right? > > > > "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hq4ecc$71q$1(a)fred.mathworks.com>... > > > Hi this is what I used (the code you describe) but what I get does not seem to be the same segmentatation > > > > > > 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); > > > r=100; > > > > > > % set(gca,'YDir','reverse') % Flip upside down. > > > > > > > > > p=ashape(x,y,r,'-g'); % <- do NOT plot... > > > ns=p.nshape; % <- # alpha shapes... > > > as=p.ashape; % <- CELL of indices ax/ay into p.x/p.y for alpha shapes ]1-ns[... > > > xc=p.x(as{1}).'; % <- ax of alpha shape #1 NOTE: transpose(!)... > > > yc=p.y(as{1}).'; > > > line(xc,yc,'marker','s','color',[0,0,0]); > > > > > > > > > sizecloseBW=size(closeBW); > > > xx=xc.'; > > > yy=yc.'; > > > mask=poly2mask(xx(:,1),yy(:,1),sizecloseBW(1),sizecloseBW(2)); > > > > > > > > > %I=medfilt2(I,[8 8]); > > > %BWs = edge(I,'canny'); > > > %figure, imshow(BWs), title('binary gradient mask'); > > > %se90 = strel('line', 4, 90); > > > %se0 = strel('line', 4, 0); > > > %BWsdil = imdilate(BWs, [se90 se0]); > > > %figure, imshow(BWsdil), title('dilated gradient mask'); > > > > > > %BWdfill = imfill(BWsdil, 'holes'); > > > %figure, imshow(BWdfill), title('binary image with filled holes'); > > > > > > %se = strel('disk',5); > > > %closeBW = imclose(BWdfill,se); > > > %figure, imshow(closeBW); > > > > > > %BWdfill = imfill(closeBW, 'holes'); > > > %figure, imshow(BWdfill), title('binary image with filled holes'); > > > > > > %seD = strel('diamond',2); > > > %BWfinal = imerode(BWdfill,seD); > > > %figure, imshow(BWfinal), title('segmented image'); > > > > > > %nieuwe manier idee: meet de achtergrond door middel van median (het is het > > > %grootste stuk in het eerste picture, en trek dat dan van segmented stukje > > > %af om te thresholden. en dit kan ook voor elk kanaal gebeuren... R G en B > > > > > > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <9b276c80-619e-4b77-8b19-f0bf8bf0d6f1(a)y14g2000yqm.googlegroups.com>... > > > > I haven't had a chance to run the new code where you extracted the > > > > polygonal envelope of the fish. Maybe you could post it (as I said, > > > > my code was left in a non-working state). But anyway, once you have > > > > that envelope, you can use poly2mask to create a binary mask and then > > > > dot-multiply it by your original. > > > > > > > > binaryMaskImage = poly2mask(yourCoordinates); > > > > maskedGrayImage = grayImage .* uint8(binaryMaskImage ); % integer > > > > types must match, eg both uint8 or both int32, etc.
From: M Ladderman on 27 Apr 2010 06:58
Hi all, The reason why I did not manage is because the imline argument did not have the createMask attribute in my toolbox version. So I update and it works now. However it is quite slow, because I use a for statement I guess to draw all lines, so for the line() it is within a blink to plot the lines, but to make the adjustments in the matrix using imline createMask it takes about a minute or so. Any clues on how to speed it up? My code is below and again thanks for the help, you could of course also not know that it was a version problem, but all other people please note to always check the version of your toolbox :S >>>>> 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); r=100; % set(gca,'YDir','reverse') % Flip upside down. p=ashape(x,y,r,'-g'); % <- do NOT plot... ns=p.nshape; % <- # alpha shapes... as=p.ashape; % <- CELL of indices ax/ay into p.x/p.y for alpha shapes ]1-ns[... xc=p.x(as{1}).'; % <- ax of alpha shape #1 NOTE: transpose(!)... yc=p.y(as{1}).'; % line(xc,yc,'marker','s','color',[0,0,0]); %xx=[xc(1,:) xc(2,:)]; %yy=[yc(1,:) yc(2,:)]; %sizecloseBW=size(closeBW); %xx=xx.'; %yy=yy.'; %figure, imshow(closeBW); %hold on; %plot(xc,yc,'color',[0,0,0]); %hold off %figure, imshow(I); %hold on; %plot(xc,yc,'color',[0,0,0]); %hold off %closeBW=newBW; %newBW(line(yc,xc))=1; %dit werkt niet maar y moet wel eerst dan x figure, imshow(closeBW); sizeyy=size(xc); for k = 1:sizeyy(1,2); hLine=(imline(gca,[xc(1,k) xc(2,k)],[yc(1,k) yc(2,k)])); binaryM=hLine.createMask(); closeBW(binaryM)=1; end figure, imshow(closeBW); filledBW=imfill(closeBW,'holes'); figure, imshow(filledBW); sizeK=size(K); filledBW=filledBW(:,1:sizeK(:,2)); maskedfishred = red .* uint8(filledBW); figure, imshow(maskedfishred); "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hqhhns$pls$1(a)fred.mathworks.com>... > Hi all, > > I am still stuck... I can plot using line() or plot() the perimeter of my ROI created using ASHAPE. But now I want to convert this to a binary mask... How to proceed?? Please help I can't seem to find how to do this. > > Cheers. > > > "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hqblnj$fvb$1(a)fred.mathworks.com>... > > Hi all, > > > > I have tried to figure it out myself but with little luck. The line function returns a handle for each line which is the length or so? But no angles, so I do not know how to use this to convert this to a binary or plot it onto my earlier binary image. The polygon option is not the way to go I guess because the segmentation seems to be worse. > > > > L > > > > "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hq7vdq$a32$1(a)fred.mathworks.com>... > > > I guess this is because the polygon drawn, draws some lines that are not the shortest lines to connect the nodes as are drawn when you use line as suggested by us. But from this line part it must be possible to mask this right? > > > > > > "M Ladderman" <mirresimons(a)gmail.com> wrote in message <hq4ecc$71q$1(a)fred.mathworks.com>... > > > > Hi this is what I used (the code you describe) but what I get does not seem to be the same segmentatation > > > > > > > > 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); > > > > r=100; > > > > > > > > % set(gca,'YDir','reverse') % Flip upside down. > > > > > > > > > > > > p=ashape(x,y,r,'-g'); % <- do NOT plot... > > > > ns=p.nshape; % <- # alpha shapes... > > > > as=p.ashape; % <- CELL of indices ax/ay into p.x/p.y for alpha shapes ]1-ns[... > > > > xc=p.x(as{1}).'; % <- ax of alpha shape #1 NOTE: transpose(!)... > > > > yc=p.y(as{1}).'; > > > > line(xc,yc,'marker','s','color',[0,0,0]); > > > > > > > > > > > > sizecloseBW=size(closeBW); > > > > xx=xc.'; > > > > yy=yc.'; > > > > mask=poly2mask(xx(:,1),yy(:,1),sizecloseBW(1),sizecloseBW(2)); > > > > > > > > > > > > %I=medfilt2(I,[8 8]); > > > > %BWs = edge(I,'canny'); > > > > %figure, imshow(BWs), title('binary gradient mask'); > > > > %se90 = strel('line', 4, 90); > > > > %se0 = strel('line', 4, 0); > > > > %BWsdil = imdilate(BWs, [se90 se0]); > > > > %figure, imshow(BWsdil), title('dilated gradient mask'); > > > > > > > > %BWdfill = imfill(BWsdil, 'holes'); > > > > %figure, imshow(BWdfill), title('binary image with filled holes'); > > > > > > > > %se = strel('disk',5); > > > > %closeBW = imclose(BWdfill,se); > > > > %figure, imshow(closeBW); > > > > > > > > %BWdfill = imfill(closeBW, 'holes'); > > > > %figure, imshow(BWdfill), title('binary image with filled holes'); > > > > > > > > %seD = strel('diamond',2); > > > > %BWfinal = imerode(BWdfill,seD); > > > > %figure, imshow(BWfinal), title('segmented image'); > > > > > > > > %nieuwe manier idee: meet de achtergrond door middel van median (het is het > > > > %grootste stuk in het eerste picture, en trek dat dan van segmented stukje > > > > %af om te thresholden. en dit kan ook voor elk kanaal gebeuren... R G en B > > > > > > > > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <9b276c80-619e-4b77-8b19-f0bf8bf0d6f1(a)y14g2000yqm.googlegroups.com>... > > > > > I haven't had a chance to run the new code where you extracted the > > > > > polygonal envelope of the fish. Maybe you could post it (as I said, > > > > > my code was left in a non-working state). But anyway, once you have > > > > > that envelope, you can use poly2mask to create a binary mask and then > > > > > dot-multiply it by your original. > > > > > > > > > > binaryMaskImage = poly2mask(yourCoordinates); > > > > > maskedGrayImage = grayImage .* uint8(binaryMaskImage ); % integer > > > > > types must match, eg both uint8 or both int32, etc. |