MATLAB super resolution function does not work
40 次查看(过去 30 天)
显示 更早的评论
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;
% 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);
1 个评论
Walter Roberson
2024-11-7,18:03
编辑:Walter Roberson
2024-11-7,18:05
The Mathworks supplied VDSR example https://www.mathworks.com/help/images/single-image-super-resolution-using-deep-learning.html does not have any vdsrLayers in it.
回答(1 个)
Gayathri
2024-11-8,7:17
编辑:Gayathri
2024-11-8,7:17
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!