Instead its type was matlab.gra​phics.prim​itive.Imag​e.

15 Ansichten (letzte 30 Tage)
clc;
clear all;
close all;
c0 = 2;
imgID = 5;
Img = imread(char(strcat(int2str(imgID),'.jpg'))) ;
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 %MARKED
[c,h] = contour(u,[0 0],'r'); %MARKED
imwrite(g, 'F:/output/filename.jpg','jpg'); %MARKED
totalIterNum=[num2str(n), ' iterations'];
title(['Final contour, ', totalIterNum]);
I = im2double(imread('output5.jpg'));
c_diag = corrcoef(I(1:end-1, 1:end-1), I(2:end, 2:end))
A=imread('output5.jpg');
ref=imread(char(strcat(int2str(imgID),'.jpg'))) ;
ssimval = ssim(A,ref);
fprintf('The SSIM value is %0.4f.\n',ssimval);

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Mai 2020
You cannot imwrite() a image() object.
IMG_to_write = uint8(normalize(Img, 'range', [0 255]));
imwrite(IMG_to_write, 'F:/output/filename.jpg', 'jpg'));
If what you want to write is the version with the contour on it, then you can either go through a bunch of trouble to interpret the contour matrix, or you can getframe() to read the rendered data off of the screen and imwrite() that.
  7 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by