File Exchange

image thumbnail

Medical Image Segmentation Using SegNet

version (1.75 MB) by Kei Otsuka
How to create, train and evaluate SegNet for medical image segmentation


Updated 06 Dec 2018

View License

Deep Learning is powerful approach to segment complex medical image.
This demo shows how to prepare pixel label data for training, and how to create, train and evaluate VGG-16 based
SegNet to segment blood smear image into 3 classes – blood parasites, blood cells and background.
医用画像処理において、Deep Learningは非常に強力なアプローチの一つです。

[Keyward] 画像処理・セグメンテーション・ディープラーニング・DeepLearning・デモ・IPCVデモ

Cite As

Kei Otsuka (2019). Medical Image Segmentation Using SegNet (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (10)

Kei Otsuka

How did you run the script?
To run a script, including all local functions, please use "Run" button, or use "Run Section" button to run individual sections in a script.

Sir i am using R2018b. Sir As i am running the code as it is. it does not find the Code for "bloodSmearColorMap " function and give error "Undefined function or variable 'bloodSmearColorMap'. ".
See the following code and error
>> imageLabeler
>> classes = [

pixelLabelID = cell(3,1);
pixelLabelID{1,1} = [2;0];
pixelLabelID{2,1} = 1;
pixelLabelID{3,1} = 3;
>> labelDir = fullfile(imgDir,'PixelLabelData');
>> pxds = pixelLabelDatastore(labelDir,classes,pixelLabelID);
>> C = readimage(pxds, 15);
>> cmap = bloodSmearColorMap;
Undefined function or variable 'bloodSmearColorMap'.


Sir i have used R2018b. Sir As i am running the code as it is. it does not find the Code for "bloodSmearColorMap " function and give error "Undefined function or variable 'bloodSmearColorMap'. ".

Kei Otsuka

Hi Muhammad,

You do not need to create another file for bloodSmearColorMap function. MATLAB should find this function in script if you use R2016b or later.
Which MATLAB version are you using?

Thanks for your nice anticipation sir,
Now i copy the code of "bloodSmearColorMap" function and paste it another file named as bloodSmearColorMap.m. this line of code "cmap = bloodSmearColorMap;" works properly,
But Now next code line give an error
>> C = readimage(pxds, 15);
>> cmap = bloodSmearColorMap;
>> B = labeloverlay(I,C,'ColorMap',cmap);
Error using labeloverlay>parseInputs (line 152)
The value of 'Colormap' is invalid. Expected Colormap to be an array with number of columns equal to 3.

Error in labeloverlay (line 87)
parsedInputs = parseInputs(varargin{:});

Please guide me, how can i fix it . i am very thankful to you sir......... waiting for your kind answer please....

Kei Otsuka

Hi Muhammad,

Thank you for the note.
bloodSmearColorMap is written in medImgSegExample3.m as a part pf supporting functions.
Please see line 277 of medImgSegExample3.m

Hi Sir, How are you, hope you will be fine and going well,
As i run this code on my system , following error come:
>> cmap = bloodSmearColorMap;
Undefined function or variable 'bloodSmearColorMap'.
Please Guide me, how can i fix it, As i search 'bloodSmearColorMap' every where in the folder and on google, But not found...

Kei Otsuka

reconstLabelSession.mファイルの 7行目 ~ 17行目を以下の内容に置き換えて頂ければと思います。

if verLessThan('matlab','9.5')
imageLabelingSession.FileName = fullfile(pwd, 'imageLabelingSession.mat');
sz = size(imageLabelingSession.ImageFilenames);
for i = 1:sz(1)
fname = imageLabelingSession.ImageFilenames{i};
[pathstr,name,ext] = fileparts(fname);
fname = fullfile(pwd, [name ext]);
imageLabelingSession.ImageFilenames{i} = fname;

save('imageLabelingSession.mat', 'imageLabelingSession')

Session の読み取り専用プロパティ 'ImageFilenames' を設定できません。

エラー: reconstLabelSession (line 14)
imageLabelingSession.ImageFilenames{i} = fname;

エラー: medImgSegExample3 (line 46)


Windows 10



updated to make it compatible with R2018b

MATLAB Release Compatibility
Created with R2017b
Compatible with R2017b to R2018b
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor