Semantic segmentation using numeric array training input

T
tiyakar_12 · May 27, 2021 · 2.3K views
Question
I have a series of P images, each MxNxC (in other words C channels) organized as a 4D numeric array X where size(X) is [M,N,C,P]. I have a corresponding series of P label maps organized as a 3D numeric array Y where size(Y) is [M,N,P].   Question: How do I convert this input to a form that can be fed to trainNetwork() in a semantic image segmentation application?   I know that trainNetwork has an input syntax,   trainedNet = trainNetwork(X,Y,layers,options) but the documentation does not discuss the format of Y for semantic segmentation problems.
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Nov 20, 2025
In case you have images with their ground truth image files, you can create image datastore and a pixelLabelDatastore and pass it to trainNetwork function using the following command.
 
 
%imds = imageDatastore(imageDirectory); %Image DataStore
%pxds = pixelLabelDatastore(pixelatedImageDirectory,classNames,pixelLabelID); %PixelLabel DataStore
trainingData = pixelLabelImageDatastore(imds,pxds); 
net = trainNetwork(trainingData,layers,opts); 

Currently the support for directly using a 4D Numeric array is not present so you may have to convert the array into set of images and store then in files accordingly.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!