MATLAB Answers

matlab code for liver segmentation

22 views (last 30 days)
Manjunath R V
Manjunath R V on 4 Sep 2020
Commented: Manjunath R V on 11 Dec 2020
Hello evryone can anybody share the matlab code for liver segmentation on CT images.
so that it is very useful to my research
Manjunath R V
Manjunath R V on 6 Dec 2020
@image analyst need to try what u provided i will update once i complete that
i have went through number of papers related to liver segmentation but what exactly i need now is dataset of CT images and liver segmentation matlab code

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 6 Dec 2020
See attached demos for finding tumors and skulls. Adapt as needed.
Also see my Image Segmentation Tutorial in my file Exchange
Image Analyst
Image Analyst on 10 Dec 2020
We don't have "a "dataset of CT images" so you're on your own for that. Surely your project sponsor has some images. I mean, why else would they hire you to do this project if they didn't have any images?
Secondly you said you read several papers that discussed liver segmentation in the link I gave you. There are hundreds of papers there and I don't have the code for any of them. I imagine that you did what I would have done, and that is to contact the authors and see if there is a way you can obtain their code (like buy it). Assuming you did that and either did not get a response, or the response was that they are not willing to help you, then you're left to write it on your own based on whatever paper you thought was best. Or you could invent your own new and improved method. But again, there is no Liver Segmentation Toolbox in MATLAB, and none of us volunteers have any code for that. If you want, the Mathworks would be delighted to write it for you. Just click on the "Consulting" link on their home page.

Sign in to comment.

Manjunath R V
Manjunath R V on 11 Dec 2020
Hello sir this is the Unet code am using to train the 256x256 size CT images.
when i tested the code after training, output image will be same as that of input image. it is unable to segment the liver from the CT image. Here am attaching the code as well as an input and output image please do the needfull.
clear all
close all
load gTruth.mat
% currentPathPixels = "C:\RVM\code_with_image_labl\Unet\PixelLabelData";
% newPathPixels = fullfile('C:\RVM\code_with_image_labl\Unet\liverPixelLabels');
% alternativePaths = {[currentPathPixels newPathPixels]};
% unresolvedPaths = changeFilePaths(gTruth,alternativePaths)
% Load training images and pixel labels into the workspace.
dataSetDir = fullfile('C:\RVM\code_with_image_labl\Unet'); %%Change the the path before run the code
imDir = fullfile(dataSetDir,'Inp_256');
pxDir = fullfile(dataSetDir,'lab256');
% Create an imageDatastore object to store the training images.
Original_imageData = imageDatastore(imDir);
% Define the class names and their associated label IData_set.
classNames = ["background","Abdomen","Liver"];
labelIData_set = [0 1 2];
% labelIData_set = cell(3,1);
% labelIData_set{1,1} = [2;0];
% labelIData_set{2,1} = 1;
% labelIData_set{3,1} = 3;
% Create a pixelLabelDatastore object to store the ground truth pixel labels for the training images.
Segmented_imageData = pixelLabelDatastore(pxDir,classNames,labelIData_set);
% Create the U-Net network.
imageSize = [256 256 1];
numClasses = 3;
Unet_Strct = unetStracture(imageSize, numClasses);
% Create a datastore for training the network for training a semantic segmentation network using deep learning
Data_set = pixelLabelImageDatastore(Original_imageData,Segmented_imageData);
% Set training options.
% % options = trainingOptions('sgdm', ...
% % 'InitialLearnRate',1e-3, ...
% % 'MaxEpochs',10, ...
% % 'VerboseFrequency',10);
options = trainingOptions('sgdm', ...
'Momentum',0.9, ...
'InitialLearnRate',8e-4, ...
'L2Regularization',0.0005, ...
'MaxEpochs',50, ...
'MiniBatchSize',3, ...
'Shuffle','every-epoch', ...
'CheckpointPath', tempdir, ...
'VerboseFrequency',2, ...
% Train the network.
newcode_net = trainNetwork(Data_set,Unet_Strct,options)
%Trained data will be saved
save newcode_net newcode_net;

Manjunath R V
Manjunath R V on 11 Dec 2020
in the above code if i add encoder depth in the Unet_Strct line like as mentioned below
Unet_Strct = unetStracture(imageSize, numClasses,Encoder depth,'1');
it is segmenting the liver but still improvement is required for reference am attaching input and output images moreover here
it is displaying 22 layers but i want 53 layers unet so needed clarification on this also.
any information provided related to the above is appreciable
Manjunath R V
Manjunath R V on 11 Dec 2020
thank you for u r suggestion sir

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by