How to write datastore to folder?

2 vues (au cours des 30 derniers jours)
Jun Er Sim
Jun Er Sim le 30 Avr 2021
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?

Réponses (1)

Anudeep Kumar
Anudeep Kumar le 5 Juin 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!

Translated by