[プロジェクト] matlab流域アルゴリズムに基づくセルのセグメンテーションとカウント[Matlabソースコード639を使用]

1.はじめに

流域アルゴリズムは、画像領域のセグメンテーション手法です。セグメンテーションプロセス中に、画像がグレースケール画像に変換されます。次に、グレースケール値を高度と見なし、下のポイントに水を注入します。この地形に基づく解釈は、
ここに画像の説明を挿入
流域の最低点に対応する最小点の3点を強調します。流域に水滴を落とすと、重力により水は最終的にこの点に収束します。注:最小サーフェスが存在する場合があり、この平面内のすべてのポイントが最小ポイントです。
流域の他の場所では、その場所からの液滴は極小値に収束します。
流域のエッジポイントは、流域と他の流域の接合部です。このポイントでの水滴は、同じ確率で任意の流域に流れます。
ここに画像の説明を挿入
上記の3つのポイントを理解した後、流域の最小ポイントに水を注入し始め、水注入が深くなるにつれて、各最小ポイントがゆっくりと外側に拡大し、2つの流域の水が収束することがわかります。合流点は私たちが必要とする流域です。

下の図から直感的に理解できます。まず、これら3つの領域に最小点が含まれ
ここに画像の説明を挿入
、次にそれらを徐々に埋めて分水界(つまり分割線)を
ここに画像の説明を挿入
取得し、分割線を取得して画像のセグメンテーションを完了します。
ここに画像の説明を挿入

第二に、ソースコード

function susanseg
clear all; close all; clc
image= imread('cell.jpg');
% 用SUSAN算法进行边缘检测
image = susan(image,4);
figure, imshow(image,[]);
%imwrite(image, './susanout/susanout.jpg');
% 将image转为二值图像保存后,用图像处理工具
% 把其背景的所有连通区域处理为黑色,即只有细
% 胞体是白色,便于细胞数目的搜索
BW = im2bw(image, graythresh(image));
bounder_area = length(find(BW==0));
%imwrite(BW, './susanout/bw.jpg');
figure, imshow(BW);


% 申明全局变量
global B Dir m n;
B = imread('./blackbackground.jpg');
B = im2bw(B, graythresh(B));
[m,n] = size(B);
figure, imshow(B);

% 细胞的总面积,即细胞所占的像素数目,包括细胞的边界
% 由于SUSAN提取出的边界已被增宽,所以将边界像素数除以2
% 来作为细胞的边界像素数目
total_area = length(find(B==1)) + bounder_area/2;
NUM = 5; % 细胞面积阈值
count = 0; % 细胞总数
% 搜索方向向量,4邻域搜索
Dir = [-1 0; 0 1; 1 0; 0 -1;];
% 搜索方向向量,8邻域搜索
%Dir = [-1 0; -1 1; 0 1; 1 1; 1 0; 1 -1; 0 -1; -1 -1;];
for i = 1:m
    for j = 1:n
        if B(i,j)==1 % 是细胞像素
            num = search(i,j,4) + 1; % 计算该细胞的像素数目
            if num>NUM
                count = count  + 1;
            else
                total_area = total_area - num; % 减掉不是细胞的面积
            end
        end
    end
end
%fid = fopen('./susanout/results.txt', 'wt');
fprintf('图像尺寸: %d * %d, SUSAN阈值: 4, 细胞面积阈值: %d\n', ...
    n, m, NUM);
fprintf('细胞总数: %d, 细胞总面积: %.2f, 平均细胞面积: %.2f\n', ...
    count, total_area, total_area/count);
%fprintf(fid,'图像尺寸: %d * %d, SUSAN阈值: 4, 细胞面积阈值: %d\n', ...
%    n, m, NUM);
%fprintf(fid,'细胞总数: %d, 细胞总面积: %.2f, 平均细胞面积: %.2f\n', ...
%    count, total_area, total_area/count);
%fclose(fid);
end
% -----------------------------------------------------------------------
% 
% This function uses the SUSAN algorithm to find edges within an image
% 
%
% >>image_out = susan(image_in,threshold)
%
%
% Input parameters ... The gray scale image, and the threshold 
% image_out .. (class: double) image indicating found edges
% typical threshold values may be from 10 to 30
%
%
%The following steps are performed at each image pixel: 
% ( from the SUSAN webpage, http://www.fmrib.ox.ac.uk/~steve/susan/susan/node4.html )
% 
% Place a circular mask around the pixel in question. 
% Calculate the number of pixels within the circular mask which have similar brightness to 
% the nucleus. These define the USAN. 
% Subtract USAN size from geometric threshold to produce edge strength image. 
%
% Estimating moments to find the edge direction has not been implemented . 
% Non-maximal suppresion to remove weak edges has not been implemented yet.
%
% example:
%
% >> image_in=imread('test_pattern.tif');
% >> image = susan(image_in,27);
% >> imshow(image,[]) 
%
%
% Abhishek Ivaturi
% 
% -------------------------------------------------------------------------
 

function image_out = susan(im,threshold)

% check to see if the image is a color image...
%im= imread('test_pattern.tif')
%threshold=27;
d = length(size(im));
if d==3
    image=double(rgb2gray(im));
elseif d==2
    image=double(im);
end

% mask for selecting the pixels within the circular region (37 pixels, as
% used in the SUSAN algorithm

mask = ([ 0 0 1 1 1 0 0 ;0 1 1 1 1 1 0;1 1 1 1 1 1 1;1 1 1 1 1 1 1;1 1 1 1 1 1 1;0 1 1 1 1 1 0;0 0 1 1 1 0 0]);  


% the output image indicating found edges
R=zeros(size(image));


% define the USAN area
nmax = 3*37/4;

% padding the image
[a b]=size(image);
new=zeros(a+7,b+7);
[c d]=size(new);
new(4:c-4,4:d-4)=image;
  
for i=4:c-4
    
    for j=4:d-4
        
        current_image = new(i-3:i+3,j-3:j+3);
        current_masked_image = mask.*current_image;
   

%   Uncomment here to implement binary thresholding

%         current_masked_image(find(abs(current_masked_image-current_masked_image(4,4))>threshold))=0;         
%         current_masked_image(find(abs(current_masked_image-current_masked_image(4,4))<=threshold))=1;


%   This thresholding is more stable
                 
                   
        current_thresholded = susan_threshold(current_masked_image,threshold);
        g=sum(current_thresholded(:));
        
        if nmax<g
            R(i,j) = g-nmax;
        else
            R(i,j) = 0;
        end
    end
end

3、実行中の結果

ここに画像の説明を挿入

四、備考

QQ 1564658423を追加するために、コードを完成させるか、記述してください

おすすめ

転載: blog.csdn.net/TIQCmatlab/article/details/115267534