Morphology-based target detection algorithm in complex background

1. Problem description:

        There are many difficulties in target detection in complex backgrounds, mainly because the background interferes with target detection, and the existence of a large amount of noise causes the failure of traditional derivative edge detection methods. Based on the above two points, this paper proposes a new algorithm for segmenting regional images and using morphological methods to detect targets; that is, first use the gray difference between the target and the background to determine the approximate area of ​​the target, segment it, and then combine multiple The structure element method carries out the accurate detection of the target. Compared with the original image segmentation and clustering algorithm segmentation experiments, the algorithm shows better anti-interference and anti-noise performance in the application examples in the article.

2. Part of the program:

 

clc;clear;close all;
 tic
I0= imread('D:\photo\01.jpg');   % 'D:\photo\5.10\DSC01587.JPG'
figure;imshow(I0);
I1=rgb2gray(I0);

I1=medfilt2(I1,[3 3]);


[x,y]=size(I1); %Find the image size
%figure,imshow(I1);
 
s=strel('disk',15); %Top-Hat transform
I2=imopen(I1,s);
%figure,imshow(I2);
title('Open operation');
I3=imsubtract(I1,I2);
figure, imshow(I3);title('High hat transformation')

se2=strel('disk',4); %Remove interference and false target points
I4=imerode(I3,se2);
%figure, imshow(I4);title('corrosion operation');
se3=strel('diamond' ,3);
I5=imdilate(I4,se3);
%figure, imshow(I5);title('expansion operation')


Seg=zeros(x,y);
 z0=max(max(I1));% find the maximum gray scale in the image
 z1=min(min(I1));% minimum gray scale 
 T=(z0+z1 )*0.5;% Set threshold
for i=1:x
   for j=1:y
       if(I5(i,j)>=T)              
           Seg(i,j)=1;% Threshold segmented image
      end
  end
end
m=Seg;
figure,subplot(2,2,1),imshow(m);
%%%%%%%%%%%%%%%%%%%%%%%%%% on the original picture Use a rectangular box to mark %%%%%%%%%%%%%%%%%%%%%%%

%subplot(2,2,2),imshow(I1);
hold on;
cou=1;
for h=1:x
    for w=1:y
     if(m(h,w)>0.5)   
      toplen = h;% topIen top ordinate
        if (cou == 1)
        tpln=toplen;% tpIn bottom ordinate
        end
      cou=cou+1;
     end
    end
end

3. Simulation conclusion:

D-10

Guess you like

Origin blog.csdn.net/ccsss22/article/details/115019704