I need to segment my input image using unet segmentation

Illustration
yun_hug_hii - 2021-04-26T13:32:26+00:00
Question: I need to segment my input image using unet segmentation

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 answered . 2025-11-20

In the imageDatastore() function there is an option to specify the reader. For example, try something like:
 
 
imds = imageDatastore('*.dcm','ReadFcn',@dicomread);


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!