File Exchange

image thumbnail

Medical Image Segmentation Using SegNet

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


Updated 19 Aug 2020

View Version History

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 (2021). Medical Image Segmentation Using SegNet (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (21)

Akshay Gore

Contact for code and support
Whatsapp +91 9464894829

1. RGB-Image-encryption-based-on-chaotic-system-and-DNA-algorithm

2. Image-encryption-based-on-chaotic-system

3. Image encryption by generating Halton sequences

4. Chaos-based-Image-Encryption

5. Text-Encryption Matlab code for AES,DES,Hybrid AES-DES and AES w/ chaos

6. Image encryption and decryption using chaotic key sequence generated by sequence of logistic map and sequence of states of Linear Feedback Shift Register

7. A New Approach of Image Encryption Using 3D Chaotic Map to Enhance Security of Multimedia Component

8. MATLAB was used for the implementation of Chaotic Digital Image Encryption.

9. Multiple-Color-Image-Encryption

10. Cryptanalyzing an Image Scrambling Encryption Algorithm of Pixel Bits.

11. Novel Image Compression encryption hybrid algorithm based on a key-controlled measurement matrix in compressive sensing.

12. An Image Encryption Scheme Based on a Hybrid Model of DNA Computing, Chaotic Systems and Hash Functions.

13. Colour image encryption algorithm combining Arnold map, DNA sequence operation, and a Mandelbrot set.

14. Advanced Encryption Standard

15. Reversible-Data-Hiding-by-Reserving-Room-Before-Encryption-MATLAB.

16. Image Encryption and Decryption Using Logistic Map Equation and Linear Feedback Shift.

17. A simple Matlab implementation of the algorithm presented in the paper: "Reversible-data-hiding-in-Encrypted-image"

17. Image encryption and encoding methods

19. DES 64bit Encryption and Decryption

20. Matlab project on blind digital watermarking and encryption.

21. Encrypting an image using Salient Object Detection and K-Means Clustering.

22. Recurrent Scale Approximation for Object Detection in CNN.

23. Object detection via a multi-region & semantic segmentation-aware CNN model.

24. R-FCN: Object Detection via Region-based Fully Convolutional Networks

25. Adversarial Examples for Semantic Segmentation and Object Detection.

26. Object Detection in Videos toolkit for VisDrone2019

27. Computational biology and medical image processing scripts and programs.
28. A MATLAB library/toolbox providing access to image registration suitable for use with medical images.
29. Lung medical image analysis and visualisation software for Matlab.
30. Medical ultrasound image processing.Carotid ultrasoung segmentation using RF data.
31. A Phase Congruency and Local Laplacian Energy Based Multi-Modality Medical Image Fusion Method in NSCT Domain.
32. Automatic tool for landmark localisation in 3D medical images.
33. Advanced-Medical-Image-Processing.
34. Recognizing and Refining the location of Individual Vessels in Segmented Retinal Images.
35. Image segmentation method on medical image is provided and tested.
36. 3D non-rigid image registration for medical and synthetic images using truncated hierarchical B-splines (THB-Splines).
37. Laplacian Re-Decomposition for Multimodal Medical Image Fusion[J]. IEEE Transactions on Instrumentation and Measurement, 2020.
38. Medical software for Processing multi-Parametric images Pipelines.
39. Prostate cancer segmentation based on MRI and PET images.
40. Image segmentation methods for biomedical purposes such as cell segmentation, blood vessel segmentation (eye blood vessels), and segmentation of brain tumors.
41. Medical Image Analysis Breast Cancer Lesion Detection.
42. Medical image enhancement based on nonlinear technique and logarithmic transform coefficient histogram matching.
43. Machine Learning: A Bayesian and Optimization Perspective.

Rijul Soans

Kei Otsuka

Hello Howard,
"bloodSmearColorMap" is local function defined in main live script.
To run a script or live script that includes local functions, please use Run button or Run Section button in the Editor or Live Editor tab.

Howard Labido

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'. ". Same problem here, and I tried to analyze solid waste.

Kei Otsuka

Hello Ali,
"partitionBloodSmearData" is local function defined in main live script.
To run a script or live script that includes local functions, please use Run button or Run Section button in the Editor or Live Editor tab.

Ali Alwaeli

Thanks you for effort
I have problem with implementation of the following function "partitionBloodSmearData.m" that is already included in your code but is not attached in the downloaded files.

alaa asem

thanks alot .
But when i run the same code without any modification.the accuracy is around 40 and loss is near to one !
could you tell me the reason of that please .

Kei Otsuka

Hello, Thank you for pointing that out. I fixed compatibility issue and fixed version can be downloaded now.

alaa asem

hi dr
when i run the code i have an error on resizing pixel label data
the error is when convert categorical to uint8 , say it not possible to convert cell to uint8
how can i solve it plz

Kei Otsuka

Hi Soheib,

If you use VGG-16 as an base network, the input need to be compatible with VGG.
You can use repmat function to create three dimensional array from gray scale images.

soheib hadj moussa

Hi, doctor
I labeled gray scale images using Pixel Label in Image Labeler app (MATLAB 2018a). I am using semantic segmentation ( to classify different objects in the images. When I ran this part of the code (I changed the third element in the imageSize to 1 because I am using the gray scale images):

Error using segnetLayers>iCheckImageSizeHasThreeElementsForVGG (line 454)
imageSize must have three elements and the third element must be 3 when creating SegNet based off of VGG-16 or

Error in segnetLayers (line 170)

Error in medImgSegExample3 (line 75)
lgraph = segnetLayers(imageSize,numClasses,'vgg16');

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.

Muhammad Shahzad

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'.


Muhammad Shahzad

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?

Muhammad Shahzad

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

Muhammad Shahzad

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...

yoshiki suzuki

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')

yoshiki suzuki

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

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

エラー: medImgSegExample3 (line 46)


Windows 10


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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!