Function IMRESIZE expected input number 2, MAP, to be a valid colormap. Valid colormaps cannot have values outside the range [0,1].
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
clc;
clear all;
close all;
c0 = 2;
imgID = 1;                                           
Img = imread(char(strcat(int2str(imgID),'.png'))) ;
Img = double(Img(:,:,1));
switch imgID
    case 1
        iterNum = 700;
        lambda1 = 1.0;
        lambda2 = 1.0;
        nu = 0.004*255*255;                                  
        initialLSF = ones(size(Img(:,:,1))).*c0;
        initialLSF(30:70,20:90) = -c0;
    case 2
        iterNum = 500;
        lambda1 = 1.0;
        lambda2 = 0.8;
        nu = 0.002*255*255;                                  
        initialLSF = ones(size(Img(:,:,1))).*c0;
        initialLSF(26:32,28:34) = -c0;
    case 3
        iterNum =800;
        lambda1 = 1.0;
        lambda2 = 1.0;
        nu = 0.003*255*255;                                  
        initialLSF = ones(size(Img(:,:,1))).*c0;
        initialLSF(15:78,32:95) = -c0;
    case 4
        iterNum = 500;
        lambda1 = 1.0;
        lambda2 = 1.0;
        nu = 0.001*255*255;                                  
        initialLSF = ones(size(Img(:,:,1))).*c0;
        initialLSF(53:77,46:70) = -c0;
    case 5
        iterNum = 700;
        lambda1 = 1.0;
        lambda2 = 0.8;
        nu = 0.001*255*255;                                  
        initialLSF = ones(size(Img(:,:,1))).*c0;
        initialLSF(47:60,86:99) = -c0;
end
u = initialLSF;
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;axis off,axis equal
title('Initial contour');
[c,h] = contour(u,[0 0],'r');
pause(0.1);
timestep = .1;                                                      
mu = 1;
epsilon = 1.0;                                                      
sigma=3.0;                                                           
K=fspecial('gaussian',round(2*sigma)*2+1,sigma);     
I = Img;
KI=conv2(Img,K,'same');                                    
KONE=conv2(ones(size(Img)),K,'same')
for n=1:iterNum
    uold = u;    
    u=RSF(u,I,K,KI,KONE, nu,timestep,mu,lambda1,lambda2,epsilon,1);
    ux = norm(u-uold);
if(  ux <= 15)
    break
end
    if mod(n,20)==0
        pause(0.1);
        imagesc(Img, [0, 255]);colormap(gray);hold on;axis off,axis equal
        [c,h] = contour(u,[0 0],'r');
        iterNum=[num2str(n), ' iterations'];
        title(iterNum);
        hold off;
    end
end
g=imagesc(Img, [0, 255]);colormap(gray);hold on;axis off,axis equal
[c,h] = contour(u,[0 0],'r');
F = getframe();
IMG_to_write = F.cdata;
imwrite(IMG_to_write, 'F:/output/filename.png', 'png');
totalIterNum=[num2str(n), ' iterations'];
title(['Final contour, ', totalIterNum]);
A = imread( 'F:/output/filename.png', 'png');
I = im2double(A);
c_diag = corrcoef(I(1:end-1, 1:end-1), I(2:end, 2:end));
ref = imread('output1.png');
A = imresize(A, size(ref)); %this line was bold
ssimval = ssim(A,ref); %this line was bold
 fprintf('The SSIM value is %0.4f.\n',ssimval); %this line was bold
0 Commenti
Risposta accettata
  Rik
      
      
 il 7 Mag 2020
        
      Modificato: Rik
      
      
 il 7 Mag 2020
  
      The image you are reading is probably an RGB image, so the size function would then return 3 elements.
size_ref=size(ref);size_ref=size_ref(1:2);
A = imresize(A, size_ref);%or: A = imresize(A, size(ref,[1 2])); (requires R2019b or newer)
ssimval = ssim(A,ref);
fprintf('The SSIM value is %0.4f.\n',ssimval);
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!