MATLAB super resolution function does not work

18 views (last 30 days)
I am trying to impreove the resolution and the quality of my pictures so that superpixel segmentation would giveme better results. I did some research and found that there is built-in model called VDSR in MATLAB. I tryed to use that, but it gives me notification "Check for missing argument or incorrect arcument data type in call to function 'predict'." Is there some obvious that I have missed?
% Step 1.5: Perform super resolution using the VDSR model
% Load the pre-trained VDSR model
netVDSR = vdsrLayers;
Unrecognized function or variable 'vdsrLayers'.
% Convert the image to grayscale and ensure the correct format
inputGrayImage = rgb2gray(imageFiltered);
inputGrayImage = im2single(inputGrayImage); % Convert to range [0, 1]
% Check the input dimensions and type
disp(size(inputGrayImage)); % Check size
disp(class(inputGrayImage)); % Check that the type is 'single'
% Perform super resolution
highResImage = predict(netVDSR, inputGrayImage);
% Visualize the original and super resolution processed image
figure;
subplot(1, 2, 1);
imshow(inputGrayImage);
title('Before Super Resolution Processing');
subplot(1, 2, 2);
imshow(highResImage);
title('After Super Resolution Processing');
% Convert back to RGB if subsequent steps require a color image
imageFiltered = cat(3, highResImage, highResImage, highResImage);

Answers (1)

Gayathri
Gayathri on 8 Nov 2024
Edited: Gayathri on 8 Nov 2024
To start with, I would like to clarify that “vdsrLayers” is not a built in model in MALTAB. The function is attached as supporting file to the MATLAB example “Single Image Super-Resolution Using Deep Learning”.
So, either you can use the supporting file or redefine the layers by referring to the example. You can also refer the below code for the same.
networkDepth = 20;
firstLayers = imageInputLayer([41 41 1],'Name','InputLayer','Normalization','none');
convLayer = convolution2dLayer(3,64,'Padding',1, ...
'WeightsInitializer','he','BiasInitializer','zeros','Name','Conv1');
relLayer = reluLayer('Name',"ReLU1");
middleLayers = [convLayer relLayer];
for layerNumber = 2:networkDepth-1
convLayer = convolution2dLayer(3,64,'Padding',[1 1], ...
'WeightsInitializer','he','BiasInitializer','zeros', ...
'Name',['Conv' num2str(layerNumber)]);
relLayer = reluLayer('Name',['ReLU' num2str(layerNumber)]);
middleLayers = [middleLayers convLayer relLayer];
end
convLayer = convolution2dLayer(3,1,'Padding',[1 1], ...
'WeightsInitializer','he','BiasInitializer','zeros', ...
'NumChannels',64,'Name',['Conv' num2str(networkDepth)]);
finalLayers = convLayer;
layers = [firstLayers middleLayers finalLayers];
Now, the predict function expects a “dlNetwork” as input so we will have convert the layers to a “dlNetwork”.
netVDSR = dlnetwork(layerGraph(layers));
In addition, we also have to convert the input image to a “dlarray” format.
dlInput = dlarray(inputGrayImage, 'SSC');
Now, these inputs can be used to predict the super resolution image.
dlhighResImage = predict(netVDSR, dlInput);
highResImage = extractdata(dlhighResImage);
I have removed the final regression layer in the “VDSR” model defined in MATLAB R2020b example as the “dlarray” function does not support the same. The latest version of MATLAB has already removed the layer in the example so it would not be an issue.
I have used the “peppers.png” image to implement the code. With all these changes I was able to obtain the output shown below.
You will have to do some post processing and train the VDSR model to get the expected output.
For more information on “dlNetwork”, please refer to the following link.
Please refer to the following link, for more information on “Single Image Super-Resolution Using Deep Learning”.
Hope you find this information helpful.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!