
liver tumor image segmentation
5 views (last 30 days)
Show older comments
hi, I have a CT image 2D and the mask for it. I need to do a MATLAB code for U-NET that I can train for this images and also test images. Can you help me with some ideas? Thank you.
2 Comments
Image Analyst
on 20 May 2023
You're welcome. That was easy. Thanks for the announcement. Good luck with it.
To learn fundamental concepts, invest 2 hours of your time here:

Yurii Volvenko
on 27 Feb 2024
Hi! I have the same task that you had. Did you find the answer to your question? I would really appreciate it if you would share it.
Answers (1)
Coo Boo
on 20 May 2023
Hi
A sample code as a starting point for training and evaluating a U-Net model:
% Load CT images and their corresponding masks
ct_images = imageDatastore('path to CT images');
masks = imageDatastore('path to masks');
% Resize images and masks to the same size
target_size = [256, 256];
ct_images = augmentedImageDatastore(target_size, ct_images);
masks = augmentedImageDatastore(target_size, masks);
% Split data into training and validation sets
[train_images, val_images] = splitEachLabel(ct_images, 0.8);
[train_masks, val_masks] = splitEachLabel(masks, 0.8);
% Create U-Net model with 4 levels and 64 filters per layer
num_levels = 4;
num_filters = 64;
unet_layers = unetLayers([256, 256, 1], num_filters, 'NumLevels', num_levels);
% Specify training options
opts = trainingOptions('adam', ...
'InitialLearnRate', 1e-4, ...
'MiniBatchSize', 16, ...
'MaxEpochs', 50, ...
'ValidationData', {val_images, val_masks}, ...
'ValidationFrequency', 10, ...
'Plots', 'training-progress');
% Train the U-Net model
trained_unet = trainNetwork(train_images, train_masks, unet_layers, opts);
% Make predictions on test images
test_images = imageDatastore('path to test images');
test_images = augmentedImageDatastore(target_size, test_images);
test_masks = predict(trained_unet, test_images);
% Evaluate performance of U-Net model
metrics = evaluateSemanticSegmentation(test_masks, test_masks);
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!