How to write datastore to folder?

3 views (last 30 days)
Jun Er Sim
Jun Er Sim on 30 Apr 2021
Answered: Anudeep Kumar on 5 Jun 2025
Hi, may I know how to show and save the segmentation output from pixel label datastore to computer folder?
pxdsResults = semanticseg(imdsTest,net,"WriteLocation",tempdir);
What should be added after this line so that the output from this can be showed and saved to folder?

Answers (1)

Anudeep Kumar
Anudeep Kumar on 5 Jun 2025
Hey Jun Er Sim
I went throught the documentation and based on the example code we can loop through the results to show them.
The code should look something like:
for i = 1:numel(pxdsResults.Files)
% Read the original image
originalImage = readimage(imdsTest, i);
% Read the segmentation result
segmentedImage = readimage(pxdsResults, i);
% Overlay the segmentation on the original image
overlayImage = labeloverlay(originalImage, segmentedImage);
% Display the result
figure;
imshow(overlayImage);
title(sprintf('Segmented Image %d', i));
end
Additionally we can save the overaly image to a specific folder as follows:
outputFolder = fullfile(pwd, 'SegmentationResults');
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
for i = 1:numel(pxdsResults.Files)
originalImage = readimage(imdsTest, i);
segmentedImage = readimage(pxdsResults, i);
overlayImage = labeloverlay(originalImage, segmentedImage);
% Save the image
outputFileName = fullfile(outputFolder, sprintf('SegmentedImage_%d.png', i));
imwrite(overlayImage, outputFileName);
end
I have attached the documentation for 'semanticseg' and 'PixelLaelDataStore' for your reference. These should provide relevant information that will help you achieve your goal.
Hope it helps!

Community Treasure Hunt

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

Start Hunting!