주요 콘텐츠

경계 검출과 모폴로지를 사용하여 세포 검출하기

이 예제에서는 경계 검출과 기본 모폴로지를 사용하여 세포를 검출하는 방법을 보여줍니다. 배경과 두드러지게 대비되는 객체는 영상에서 쉽게 검출할 수 있습니다.

1단계: 영상 읽어 들이기

전립선암 세포 영상인 cell.tif 영상을 읽어 들입니다. 이 영상에는 세포가 두 개 있지만, 완전히 보이는 세포는 하나뿐입니다. 목표는 완전히 보이는 세포를 검출 또는 분할하는 것입니다.

I = imread('cell.tif');
imshow(I)
title('Original Image');
text(size(I,2),size(I,1)+15, ...
    'Image courtesy of Alan Partin', ...
    'FontSize',7,'HorizontalAlignment','right');
text(size(I,2),size(I,1)+25, ....
    'Johns Hopkins University', ...
    'FontSize',7,'HorizontalAlignment','right');

Figure contains an axes object. The hidden axes object with title Original Image contains 3 objects of type image, text.

2단계: 완전한 세포 검출하기

분할할 객체는 배경 영상과 대비 차이가 큽니다. 대비 변화는 영상 기울기를 계산하는 연산자를 통해 검출할 수 있습니다. 분할된 세포를 포함하는 이진 마스크를 만들려면 기울기 영상을 계산하고 임계값을 적용하십시오.

edge와 Sobel 연산자를 사용하여 임계값을 계산합니다. 임계값을 조정하고 edge를 다시 사용하여, 분할된 세포를 포함하는 이진 마스크를 얻습니다.

[~,threshold] = edge(I,'sobel');
fudgeFactor = 0.5;
BWs = edge(I,'sobel',threshold * fudgeFactor);

결과로 생성된 이진 기울기 마스크를 표시합니다.

imshow(BWs)
title('Binary Gradient Mask')

Figure contains an axes object. The hidden axes object with title Binary Gradient Mask contains an object of type image.

3단계: 영상 팽창시키기

이진 기울기 마스크에는 영상의 고대비를 나타내는 선이 표시됩니다. 이러한 선으로 원하는 객체의 윤곽을 알기가 어렵습니다. 원본 영상과 비교해 보면, 기울기 마스크의 객체를 둘러싼 선들 간에 간격이 있는 것을 알 수 있습니다. 이러한 선 간격은 선형 구조 요소를 사용하여 Sobel 영상을 팽창시키면 사라집니다. strel 함수를 사용하여 두 개의 직교하는 선형 구조 요소를 만듭니다.

se90 = strel('line',3,90);
se0 = strel('line',3,0);

세로 구조 요소 다음에 가로 구조 요소를 사용하여 이진 기울기 마스크를 팽창시킵니다. imdilate 함수는 영상을 팽창시킵니다.

BWsdil = imdilate(BWs,[se90 se0]);
imshow(BWsdil)
title('Dilated Gradient Mask')

Figure contains an axes object. The hidden axes object with title Dilated Gradient Mask contains an object of type image.

4단계: 내부 간격 채우기

팽창된 기울기 마스크는 세포 윤곽선이 꽤 깔끔하게 정돈되었지만, 셀 내부에 아직도 구멍이 있습니다. 이러한 구멍을 채우려면 imfill 함수를 사용하십시오.

BWdfill = imfill(BWsdil,'holes');
imshow(BWdfill)
title('Binary Image with Filled Holes')

Figure contains an axes object. The hidden axes object with title Binary Image with Filled Holes contains an object of type image.

5단계: 테두리에 접한 객체 제거하기

원하는 세포를 분할했지만, 발견된 또 다른 객체가 있습니다. 영상의 테두리에 접한 모든 객체는 imclearborder 함수를 사용하여 제거할 수 있습니다. 대각 연결을 제거하려면 imclearborder 함수의 연결성을 4로 설정하십시오.

BWnobord = imclearborder(BWdfill,4);
imshow(BWnobord)
title('Cleared Border Image')

Figure contains an axes object. The hidden axes object with title Cleared Border Image contains an object of type image.

6단계: 객체 평활화하기

마지막으로, 분할된 객체가 자연스럽게 보이도록 다이아몬드 구조 요소로 영상을 두 번 침식시켜 객체를 평활화합니다. strel 함수를 사용하여 다이아몬드 구조 요소를 만듭니다.

seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
imshow(BWfinal)
title('Segmented Image');

Figure contains an axes object. The hidden axes object with title Segmented Image contains an object of type image.

7단계: 분할 시각화하기

labeloverlay 함수를 사용하여 원본 영상 위에 마스크를 표시할 수 있습니다.

imshow(labeloverlay(I,BWfinal))
title('Mask Over Original Image')

Figure contains an axes object. The hidden axes object with title Mask Over Original Image contains an object of type image.

분할된 객체를 표시하는 또 다른 방법은 분할된 세포 주위에 윤곽선을 그리는 것입니다. bwperim 함수를 사용하여 윤곽선을 그립니다.

BWoutline = bwperim(BWfinal);
Segout = I; 
Segout(BWoutline) = 255; 
imshow(Segout)
title('Outlined Original Image')

Figure contains an axes object. The hidden axes object with title Outlined Original Image contains an object of type image.

참고 항목

| | | | | |

도움말 항목