I need to segment my input image using unet segmentation

Y
yun_hug_hii · Apr 26, 2021 · 2.2K views
Question
where inp is my input image     inp=b DatasetPath=fullfile('C:\Users\Desktop\to'); imds=imageDatastore(DatasetPath, 'IncludeSubfolders', true,... 'LabelSource','foldernames','fileextension',{'.dcm'}); labelDir = fullfile(DatasetPath,'testImages'); I = readimage(imds,1); I = histeq(I); imshow(I) classes = [ "MALIGNANT","BENIGN" ]; labelIDs=[255 0] inputlayer = imageInputLayer([512 512 1],'Name','inp') numFilters = 64; numLayers = 16; layers = [ ... imageInputLayer([512 512 1]) convolution2dLayer(5,20) batchNormalizationLayer reluLayer maxPooling2dLayer(2,'Stride',2) convolution2dLayer(5,20) batchNormalizationLayer reluLayer maxPooling2dLayer(2,'Stride',2) transposedConv2dLayer(4,numFilters,'Stride',2,'Cropping',1); convolution2dLayer(5,20) batchNormalizationLayer reluLayer transposedConv2dLayer(4,numFilters,'Stride',2,'Cropping',1); convolution2dLayer(5,20) batchNormalizationLayer reluLayer convolution2dLayer(5,20) fullyConnectedLayer(4) softmaxLayer pixelClassificationLayer ] % pxds = pixelLabelDatastore(labelDir,classes,labelIDs); options = trainingOptions('sgdm', ... 'InitialLearnRate',0.01, ... 'MaxEpochs',1, ... 'Shuffle','every-epoch', ... 'ValidationFrequency',30, ... 'Verbose',false); net=trainNetwork(imds,layers,options); res = activations(net,inp,net.Layers(numLayers-1).Name,'OutputAs','channels'); I = read(imds); % C = read(pxds) C = semanticseg(I, net); % Overlay pixel label data on the image and display. B = labeloverlay(I, C); figure(12) imshow(B) I got error @ Error using trainNetwork Not enough input arguments.   Error in net=trainNetwork(imds,layers,options);I
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 11, 2026
In the imageDatastore() function there is an option to specify the reader. For example, try something like:
 
 
imds = imageDatastore('*.dcm','ReadFcn',@dicomread);
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!