MATLAB 영상처리 활용

[MATLAB 영상처리 활용] 검출된 cell(세포) 컬러 하이라이트 주기 - cell extraction

toyprojects 2023. 9. 2. 02:13

 

 

IBA1_EDF_ #2_SN_L_3_Image 3_EDF_ch00 (출처1)

 

위의 이미지는 Anwer et al., (출처 1) 의 페이퍼에서 제시하는 microglial cell을 기록한 영상파일

입니다. ( 자세한 사항은 본 블로그의 [MATLAB 영상처리 활용] Microglial cell segmentation review

참조해 주시고, 위의 이미지는 본 블로그 맨밑 출처 1에서 제시하는 이미지로써 이곳에 가셔서 다운로드 

받을 수 있습니다.  )

 

만일 이미지 프로세싱의 목적이 위의 영상에서 microglial cell을 검출(extraction) 하는것이라면,

최종결과 중의 하나로써 검출된 cell(세포)의 위치를 지정된 색상으로 덧입혀 표시하는 결과 이미지일

것입니다. 보통 cell(세포)의 검출에는 black & white mask가 활용되므로 이를 이용해 간단한 예시를

보이겠습니다.

 

우선 위의 이미지에서 임의로 cell(세포) 하나를 선택하겠습니다 - 이미지의 빨간색 dash 라인의 네모상자

참조. 그리고 임의로 선택한 cell(세포)을 상대로 기본값의 Otsu thesholding을 수행합니다. 

( 코드에서 쓰인 이미지는 이곳 가셔서 다운로드 받을 수 있습니다. )

 

 

좌: 입력 이미지, 우: Otsu thresholding을 이용한 BW mask

 

 

img = imread('IBA1_EDF_#2_SN_L_3_Image 3_EDF_ch00.tif');

% image region selection 
% [x:769, y:827] -> [x:985, y:1007]
img_cell = img(827:1007, 769:985,:);
img_gray = rgb2gray(img_cell);          % convert from RGB to grayscale image data
img_gray = im2double(img_gray);         % convert from uint8 to double type data

% BW by Otsu algorithm
level = graythresh(img_gray);
img_BW = ~imbinarize(img_gray,level);
out = imtile({img_cell,img_BW});
figure; imshow(out);

 

 

앞서 말한대로 원본 이미지상에 임의의 구역을 ROI (region of interest) 로 지정하였고, 

x, y 좌표값을 직접 입력하여 crop 하였습니다. 그리고 이것을 이진화 하기위해 grayscale 변환 ->

변수의 double 형 변환 -> Otsu level 연산 -> 이미지의 binarization 순으로 명령을 수행하였습니다. 

 

이진화를 거친 이미지에서 cell(세포) 영역을 하얀색(픽셀값 'logical' 1)으로 지정하기 위해 imbinarize( )

명령어 앞에 반전(inverse) 기호 ' ~ '  를 주었습니다.

마지막으로 원본 이미지와 이진화된 BW 이미지를 함께 표시하기 위해 imtile( ) 명령어를 사용하였습니다.

( montage( ) 또한 imtile( ) 과 동일한 명령을 수행 합니다. )

 

 

이제는 3차원의 RGB컬러 원본 이미지를 채널별로 분리하여 이진화된 BW 이미지와 겹치기를 통해 

컬러 하이라이트를 적용할 영역을 지정합니다. 

즉, 이진화된 BW 이미지의 cell(세포) 영역은 픽셀값 'logical' 1 을 갖고 배경은 'logical' 0 을 갖기 때문에

이를 원본 이미지의 픽셀 matrix에 적용 한다면 cell(세포) 영역만이 true 로써  

- '&' 연산: 픽셀값 & logical 1 - 직접적인 픽셀 (x, y) 좌표를 선택할 수 있고, 따라서 특정 색상값을 지정할

수 있습니다. 밑의 결과 이미지는 cell(세포) 영역에 초록색으로 컬러 하이라이트를 준 모습입니다.

 

 

MATLAB 코드의 순서는,

1) 먼저 RGB컬러 이미지를 3개의 색상채널로 분리 ( imsplit( ) 이용 ) 하였으며,

2) 분리된 각 채널 이미지에 " img_BW " 가 입력 파라메터로써 픽셀 범위지정을 하고,    

3) G 채널(초록색) 에만 최대값 255를, 나머지 색상채널에는 최소값 0을 대입 하였습니다.

4) 마지막으로 분리되었던 3개의 채널 이미지를 다시 하나의 RGB컬러 이미지로 합쳤습니다.

 

 

좌: 입력 이미지, 우: BW mask에 초록색을 적용한 결과

 

 

% bit-wise computation
[img_cell_R,img_cell_G,img_cell_B] = imsplit(img_cell);
img_cell_R(img_BW) = 0;    
img_cell_G(img_BW) = 255;  
img_cell_B(img_BW) = 0;    
img_cell_highlighted = cat(3,img_cell_R,img_cell_G,img_cell_B);

out = imtile({img_cell,img_cell_highlighted});
figure; imshow(out);

 

본 포스트에서는 임의로 선택한 cell(세포)에 대해 컬러 하이라이트를 주었지만, 일반적으로

사용되는 cell extraction (세포 검출) 프로그램/알고리즘에서는 대상 이미지에서 자동으로

cell(세포)를 검출하고, 검출된 결과에 컬러 하이라이트를 적용합니다. 

이러한 자동화된 cell extraction (세포 검출) 프로그램/알고리즘은 앞으로 중급과정에서 

다루도록 하겠습니다.

 

 

 

마지막으로 본 글에 쓰인 모든 MATLAB 코드는 밑에 표시해 두었습니다.

 

img = imread('IBA1_EDF_#2_SN_L_3_Image 3_EDF_ch00.tif');

% image region selection 
% [x:769, y:827] -> [x:985, y:1007]
img_cell = img(827:1007, 769:985,:);
img_gray = rgb2gray(img_cell);          % convert from RGB to grayscale image data
img_gray = im2double(img_gray);         % convert from uint8 to double type data

% BW by Otsu algorithm
level = graythresh(img_gray);
img_BW = ~imbinarize(img_gray,level);
out = imtile({img_cell,img_BW});
figure; imshow(out);

% bit-wise computation
[img_cell_R,img_cell_G,img_cell_B] = imsplit(img_cell);
img_cell_R(img_BW) = 0;    
img_cell_G(img_BW) = 255;  
img_cell_B(img_BW) = 0;    
img_cell_highlighted = cat(3,img_cell_R,img_cell_G,img_cell_B);

out = imtile({img_cell,img_cell_highlighted});
figure; imshow(out);

 

 

 

 

출처1: https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0284480#

 

A comparison of machine learning approaches for the quantification of microglial cells in the brain of mice, rats and non-human

Microglial cells are brain-specific macrophages that swiftly react to disruptive events in the brain. Microglial activation leads to specific modifications, including proliferation, morphological changes, migration to the site of insult, and changes in gen

journals.plos.org