MATLAB Examples

Contents

テクスチャ情報を利用した医用画像のセグメンテーション

Medical image segmentation using texture analysis

#1, 血液塗抹検査画像から、病原虫が寄生した赤血球のみ抽出する (Extract where the parasite blood cell is from blood smear images) #2, 足首のCT画像から、特定の組織のみ抽出する (Extract area that has specific texture pattern from CT image)

clear all, close all, imtool close all, clc;

画像読み込み

Loading a JPEG images

画像ソース(Image source) : 米国CDC DPDx Parasite Image Library

%<https://www.cdc.gov/dpdx/malaria/index.html>
img = cell(2,2);
img{1,1} = imread('Plasmodium.jpg');
img{1,2} = 'Plasmodium';
img{2,1} = imread('Babesia.jpg');
img{2,2} = 'Babesia';
figure, imshowpair(img{1}, img{2}, 'montage');
text(size(img{1,1}, 2), size(img{1,1},1)+15, ...
    '画像ソース: 米国CDC DPDx Parasite Image Library', ...
    'FontSize', 8, ...
    'HorizontalAlignment', 'left');
text(size(img{1,1}, 2), size(img{1,1},1)+35, ...
    '<https://www.cdc.gov/dpdx/malaria/index.html>', ...
    'FontSize', 8, ...
    'HorizontalAlignment', 'left');

各テクスチャーのグレースケール共起行列を見てみましょう

Create gray-level co-occurrence matrix from images

sz = [3 3];
figure; subplot(1,2,1);
for k = 1:2
    % 共起行列計算
    glcm = graycomatrix(rgb2gray(img{k,1}), 'Offset', sz);
    % プロット
    subplot(1,2,k);
    imagesc(glcm);
    title(img{k,2})
    axis image;
    colorbar;
end

GLCM生成

Create gray-level co-occurrence matrix from Plasmodium image

[glcm, SI] = graycomatrix(rgb2gray(img{1,1}), 'Offset', sz);

特定のパタンを抽出

Extract area that has specific matrix pattern

ptn = [5 5];
bs = floor((sz+1) / 2);
fun = @(x) selGlcm(x, ptn, sz+1);
bw = nlfilter(SI, sz+1, fun);

figure, imshow(bw)

モルフォロジー処理で穴埋め、整形

Morphologically close image to clearn up

bw2 = imclose(bw, strel('disk', 10));
imshow(bw2)

結果をオーバーレイ表示

Burn binary mask into image

I2 = imoverlay(img{1,1}, ~bw2, 'white');
figure, imshow(I2)

動的輪郭を使用し、領域境界を抽出

Use activecontour to get more precise contour of parasite cell

bw2 = activecontour(rgb2gray(img{1,1}), bw, 100);
figure, imshow(bw2)
title('Segmented Image');

結果をオーバーレイ表示

Burn binary mask into image

I2 = imoverlay(img{1,1}, ~bw2, 'white');
figure, imshow(I2)

#2, 足首のCT画像から、特定の組織のみ抽出する

     (Extract area that has specific texture pattern from CT image)
clear all, close all, clc

画像データ読み込み

Loading a dicom images

gray = dicomread('CT-MONO2-16-ankle.dcm');
gray = imadjust(gray);
imtool(gray)

GLCM生成

Create gray-level co-occurrence matrix from Plasmodium image

sz = [0 20];
[glcm, SI] = graycomatrix(gray, 'Offset', sz, 'NumLevels', 10);
figure, imshow(SI, [])

生起行列を可視化

Display created GLCM

figure, imagesc(glcm);
axis image;
title (['共起行列']);
colorbar;

特定のパタンを抽出

Extract area that has specific matrix pattern

ptn = [5 10];
bs = floor((sz+1) / 2);
fun = @(x) selGlcm(x, ptn, sz+1);
bw = nlfilter(SI, sz+1, fun);
figure, imshow(bw)

細かいオブジェクトは除去は除去

Use morphological operations to clearn up

bw = bwareaopen(bw,2);
bw = imclose(bw, strel('disk', 15));
%10pixelシフト
bw = [bw(:,11:end) zeros(512,10)];
figure, imshowpair(gray, bw);

動的輪郭を使用し、領域境界を抽出

Use activecontour to get more precise contour

bw2 = activecontour(gray, bw, 50, 'edge', 'ContractionBias',-0.4, 'SmoothFactor', 0.1);
bw2 = imclose(bw2, strel('disk', 5));
figure, imshow(bw2)
title('Segmented Image');
figure, imshowpair(gray, bw2);

該当箇所をハイライト表示

Get segmented area highlited

gray2 = im2uint16(gray);
gray2(~bw2) = gray2(~bw2) * 0.3;
figure, imshow(gray2,[])

注釈挿入

Annotate image

stats = regionprops(bw2, 'BoundingBox');
gray3 = insertObjectAnnotation(gray2,'rectangle',stats.BoundingBox,'Segmented Area',...
    'TextBoxOpacity',0.9,'FontSize',18);
figure, imshow(gray3)