Creating a 3D surface plot from array data

I have this script
clear
img = imread('cameraman.tif');
Mean = 0.01:0.01:0.05;
hsize = 3:1:25;
for m = 1:length(Mean)
for h = 1:length(hsize)
V=0.01;
noise = imnoise(img,'gaussian',Mean(m),V);
[peaksnr, snr] = psnr(noise,img);
nsr = 1/snr;
PSF = fspecial('average',hsize(h));
AverageBlur = imfilter(img,PSF,'replicate','same','conv');
NoiseyBlurred = imfilter(noise,PSF,'replicate','same','conv');
NoiseyBlurredImage = NoiseyBlurred;
BlindDeconv = deconvblind(NoiseyBlurredImage,PSF,15);
LucyFilter = deconvlucy(NoiseyBlurredImage,PSF,15);
WNRFilter = deconvwnr(NoiseyBlurredImage,PSF,nsr);
RegularFilter = deconvreg(NoiseyBlurredImage,PSF,NPowerInt);
PSNRBlurred = psnr(NoiseyBlurredImage,img);
PSNRBlind = psnr(BlindDeconv,img);
PSNRLucy = psnr(LucyFilter,img);
PSNRWNR = psnr(WNRFilter,img);
PSNRReg = psnr(RegularFilter,img);
Blur(h,m)= (40-PSNRBlurred)/40;
Blind(h,m)=PSNRBlind;
Lucy(h,m)=PSNRLucy;
WNR(h,m)=PSNRWNR;
Reg(h,m)=PSNRReg;
end
end
It saves the PSNR value for each hsize and mean in 25x5 array like this:
Lucy =
21.6467 21.4919 21.1253 20.7971 20.3298
22.2624 22.1446 21.7016 21.3296 20.7955
22.4250 22.1990 21.8411 21.4450 21.0195
Each column has 25 values which i cut short for space. The blurred error (denoted 'Blur') saves in the same way.
I am trying to plot a 3D surface/mesh of the data, where for each column PSNR vs error is plotted, rather than just a 2D line plot with 5 lines over the top of eachother. Is there a way to do this?
Edit: Attached Image of 2D plot to help with clarity of the question. Can i make a graph like this but 3D to be able to see all the lines (ideally as a surface) and with the new axis being the 'Mean'. The 5 lines are due to the 5 Mean values. The error and psnr value changes with each hsize, i.e. 23 x,y values per line. Allowing me to see how both hsize and mean affect the PSNR value.
Apologies for the lack of clarity and specificity in the original question, hopefully this helps clear things up.

 Respuesta aceptada

Star Strider
Star Strider el 30 de Abr. de 2020
Try this:
figure
surf(Lucy)
grid on
or:
figure
mesh(Lucy)
grid on
The ‘x’ and ‘y’ axes are in units of the relevant indices, since ‘x’ and ‘y’ vectors or matrices defining them otherwise are not provided.

6 comentarios

Steven Harkness
Steven Harkness el 30 de Abr. de 2020
Thanks for the quick reply!
I just tried it and although it is the right kind of plot I also need to include the values from Blur in the plot too. I looked into surf and tried surf(Lucy,Blur,z) with z = 1:1:5 to represent the 5 columns but that wouldnt plot as z was a vector not a matrix.
My pleasure!
You need to be more specific. If you want to plot both ‘Lucy’ and ‘Blur’, on the same axes, probably the easiest way is:
figure
surf(Lucy)
hold on
surf(Blur)
hold off
grid on
.
Steven Harkness
Steven Harkness el 1 de Mayo de 2020
Apologies for the question not being specifc and clear enough. I've edited it to try and help clear things up. That did plot them both but not in the way i meant (again sorry for not making it clear), the edit in the question should show what im trying to do. Thanks again
The ribbon function may be what you want. Since you mentioned that your arrays are (25x5), this will plot them using the row size as the independent variable:
Lucy = [ 21.6467 21.4919 21.1253 20.7971 20.3298
22.2624 22.1446 21.7016 21.3296 20.7955
22.4250 22.1990 21.8411 21.4450 21.0195];
figure
ribbon((1:size(Lucy,1)),Lucy, 0.1)
grid on
Another option:
x = (ones(size(Lucy,2),1)*(1:size(Lucy,1)))';
y = ones(size(Lucy,1),1)*(1:size(Lucy,2));
x = [x; nan(1,size(x,2))];
y = [y; nan(1,size(y,2))];
Lucy = [Lucy; nan(1,size(Lucy,2))];
figure
plot3(x(:),y(:),Lucy(:))
grid on
Experiment with them to get the result you want.
.
Steven Harkness
Steven Harkness el 1 de Mayo de 2020
Ribbon is perfect, thank you!
Star Strider
Star Strider el 1 de Mayo de 2020
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Printing and Saving en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Abr. de 2020

Comentada:

el 1 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by