Matlab显微镜图像上的粒子间接触检测

时间:2019-05-03 19:48:24

标签: matlab image-processing object-detection detection

我有一张乳剂液滴的照片。我要检测液滴间的接触,并针对每个色块绘制强度曲线。 Emulsion 在下面的代码中,我首先手动选择一个ROI,尝试在该ROI上检测整个补丁。请注意,对于某些色块,接触线上的强度大约是一半的二聚体:我想测量两个平台强度。

clear all
close all
fname='MTE_20190417_slice7.tif' % mind to reove the '.png' in the name of the attached file
info=imfinfo(fname);
num_images=numel(info);
flagfig=1;
k=1;% for future purposes, on a whole stack
A=imread(fname, k);
B=255-A;
figure(flagfig);imshow(B)
hold on
%% define an ROI
cursors = round(ginput(2));
plot(cursors(:,1),[1,1].*cursors(1,2),'r--')
plot(cursors(:,1),[1,1].*cursors(2,2),'r--')
plot(cursors(1,1).*[1,1],cursors(:,2),'r--')
plot(cursors(2,1).*[1,1],cursors(:,2),'r--')
%% crop the ROI
x_ROI = cursors(:,1);
y_ROI = cursors(:,2);
ROI = imcrop(B,[min(x_ROI), min(y_ROI), abs(x_ROI(2)-x_ROI(1)), abs(y_ROI(2)-y_ROI(1))]);%  specifies the size and position of the crop rectangle as [xmin ymin width height]
if flagfig~=0
    figure(flagfig+1)
    imshow(ROI)
    hold on
end
%% find the median line of the patch
binaryImage=edge(ROI,'canny');
AA=bwmorph(binaryImage, 'thicken',1);
[H,T,R] = hough(AA);
if flagfig~=0
    figure(flagfig+2)
    imshow(H,[],'XData',T,'YData',R,...
        'InitialMagnification','fit');
    xlabel('\theta'), ylabel('\rho');
    axis on, axis normal, hold on;
end
P  = houghpeaks(H,5,'threshold',ceil(0.8*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
if flagfig~=0
    figure(flagfig+2)
    plot(x,y,'s','color','white');
end
lines = houghlines(AA,T,R,P,'FillGap',5,'MinLength',7);
if flagfig~=0
    figure(flagfig+3)
    imshow(binaryImage), hold on
    figure(flagfig+4)
    imshow(AA), hold on
end
xy=nan(2,2,length(lines));
len=nan(length(lines),1);
for k = 1:length(lines)
    xy(:,:,k) = [lines(k).point1; lines(k).point2];
    if flagfig~=0
        figure(flagfig+3)
        hold on
        plot(xy(:,1,k),xy(:,2,k),'LineWidth',2,'Color','green');
        % Plot beginnings and ends of lines
        plot(xy(1,1,k),xy(1,2,k),'x','LineWidth',2,'Color','yellow');
        plot(xy(2,1,k),xy(2,2,k),'x','LineWidth',2,'Color','red');
    end
    % Determine the endpoints of the longest line segment
    len(k) = norm(lines(k).point1 - lines(k).point2);
end
[xy_long, kmax]=max(len);% xy_long=len(kmax); % Longer length
xy_long2 =max(len(len<xy_long));% second longer length
kmax2=find(round(len*100)==round(xy_long2*100));%compute corresponding index
%
line1=xy(:,:,kmax);
line2=xy(:,:,kmax2);
linemed=(line1+line2)/2;
if flagfig~=0
    figure(flagfig+1)
    plot(linemed(:,1),linemed(:,2),'linewidth',2,'Color','m')
    figure(flagfig+3)
    plot(xy(:,1,kmax),xy(:,2,kmax),'LineWidth',2,'Color','r');
    plot(xy(:,1,kmax2),xy(:,2,kmax2),'LineWidth',2,'Color','r');
end
%% compute intensity profile along this line
intprofile=improfile(255-ROI,linemed(:,1),linemed(:,2),'bilinear');
if flagfig~=0
    figure(flagfig+5)
    plot(intprofile)
    hold on
end

我已经尝试了边缘功能的几种设置,霍夫峰阈值,边缘图像的增粗,但是代码仍然不够鲁棒:有时,根据我如何选择主图像上的ROI(接触贴片)未完全检测到(因此强度分布不完整)。 另外,我仍然不知道如何拟合强度分布(我想)应该具有的梯形轮廓,以便同时具有强度值(高和低,当后者存在时)。 谢谢您的帮助。

0 个答案:

没有答案