计数蜥蜴的鳞片 [英] Counting the squama of lizards

查看:281
本文介绍了计数蜥蜴的鳞片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一位生物学家朋友问我能不能帮他做一个节目为算鳞(这是正确的翻译?)的蜥蜴。

A biologist friend of mine asked me if I could help him make a program to count the squama (is this the right translation?) of lizards.

他给我发了一些图片,我尝试了Matlab的一些事情。对于某些图像,它比其他更难,例如当有更暗(黑)的区域。至少在我的方法。我敢肯定,我可以在这里得到一些有用的帮助。我应该如何改善呢?我是否采取了正确的方法呢?

He sent me some images and I tried some things on Matlab. For some images it's much harder than other, for example when there are darker(black) regions. At least with my method. I'm sure I can get some useful help here. How should I improve this? Have I taken the right approach?

这些都是一些图片。

我按照图像处理及计数采用MATLAB <得到了最好的结果/ A>。它基本上旋转图像分为黑色和白色,然后门槛吧。但我确实加了一点侵蚀。

I got the best results by following Image Processing and Counting using MATLAB. It's basically turning the image into Black and white and then threshold it. But I did add a bit of erosion.

这里的code:

img0=imread('C:...\pic.png');

img1=rgb2gray(img0);

%The output image BW replaces all pixels in the input image with luminance greater than level with the value 1 (white) and replaces all other pixels with the value 0 (black). Specify level in the range [0,1]. 
img2=im2bw(img1,0.65);%(img1,graythresh(img1));

imshow(img2)
figure;

 %erode
 se = strel('line',6,0);     
 img2 = imerode(img2,se);
 se = strel('line',6,90);   
 img2 = imerode(img2,se);
 imshow(img2)
figure;

imshow(img1, 'InitialMag', 'fit')

% Make a truecolor all-green image. I use this later to overlay it on top of the original image to show which elements were counted (with green)
 green = cat(3, zeros(size(img1)),ones(size(img1)), zeros(size(img1)));
 hold on
 h = imshow(green); 
 hold off


%counts the elements now defined by black spots on the image
[B,L,N,A] = bwboundaries(img2);
%imshow(img2); hold on;
set(h, 'AlphaData', img2)
text(10,10,strcat('\color{green}Objects Found:',num2str(length(B))))
figure;



%this produces a new image showing each counted element and its count id on top of it.
imshow(img2); hold on;
colors=['b' 'g' 'r' 'c' 'm' 'y'];
for k=1:length(B),
     boundary = B{k};
     cidx = mod(k,length(colors))+1;
     plot(boundary(:,2), boundary(:,1), colors(cidx),'LineWidth',2);
     %randomize text position for better visibility
     rndRow = ceil(length(boundary)/(mod(rand*k,7)+1));
     col = boundary(rndRow,2); row = boundary(rndRow,1);
     h = text(col+1, row-1, num2str(L(row,col)));
     set(h,'Color',colors(cidx),'FontSize',14,'FontWeight','bold');
end
figure; 
spy(A);

这些都是一些结果。其中的左上角,你可以看到有多少计数。

And these are some of the results. One the top-left corner you can see how many were counted.

另外,我觉得有绿色标记的计元素,至少用户可以知道哪些必须手动计数是很有用的。

Also, I think it's useful to have the counted elements marked in green so at least the user can know which ones have to be counted manually.

推荐答案

还有,你应该考虑一个路由:的分水​​岭分割。这里是一个快速和肮脏的例子与你的第一个图像(它假定你有IP工具箱):

There is one route you should consider: watershed segmentation. Here is a quick and dirty example with your first image (it assumes you have the IP toolbox):

raw=rgb2gray(imread('lCeL8.jpg'));

Icomp = imcomplement(raw);
I3 = imhmin(Icomp,20);
L = watershed(I3);
%%
imagesc(L);
axis image

与色彩表显示结果:

Result shown with a colormap:

您可以再算上细胞如下:

You can then count the cells as follows:

count = numel(unique(L));

的好处之一是,它可以直接输送到 regionprops ,并给大家介绍了个人的鳞片漂亮的细节:

One of the advantages is that it can be directly fed to regionprops and give you all the nice details about the individual 'squama':

r=regionprops(L, 'All');
imshow(raw);

for k=2:numel(r)
    if r(k).Area>100 % I chose 100 to filter out the objects with a small are.
        rectangle('Position',r(k).BoundingBox, 'LineWidth',1, 'EdgeColor','b', 'Curvature', [1 1]); 
    end
end

,你可以用它来监控上/下分割:

Which you could use to monitor over/under segmentation:

注:特别感谢@jucestain帮助与适当的访问到田间地头,在研究结构的这里

Note: special thanks to @jucestain for helping with the proper access to the fields in the r structure here

这篇关于计数蜥蜴的鳞片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆