Storing a matrix in a file.

1 visualizzazione (ultimi 30 giorni)
Ankrutee Arora
Ankrutee Arora il 22 Dic 2022
Risposto: dpb il 22 Dic 2022
close all;
location = '/MATLAB Drive/PE/Frames/'; % folder in which your images exists
ds = imageDatastore(location) ; % Creates a datastore for all images in your folder
i=1;
array=zeros(65,1080,1920);
while hasdata(ds)
Img = readimage(ds,i);
%i=i+1;
%Img = read(ds); % read image from datastore
%figure, imshow(img); % creates a new window for each image
%Img = imread('Circle.png'); % real miscroscope image of cells
Img=double(Img(:,:,1));
%% parameter setting
timestep=25; % time step
mu=0.2/timestep; % coefficient of the distance regularization term R(phi)
iter_inner=5;
iter_outer=40;
lambda=5; % coefficient of the weighted length term L(phi)
alfa=15; % coefficient of the weighted area term A(phi)
epsilon=150; % papramater that specifies the width of the DiracDelta function
sigma=1.5; % scale parameter in Gaussian kernel
G=fspecial('gaussian',15,sigma);
Img_smooth=conv2(Img,G,'same'); % smooth image by Gaussiin convolution
[Ix,Iy]=gradient(Img_smooth);
f=Ix.^2+Iy.^2;
g=1./(1+f); % edge indicator function.
% initialize LSF as binary step function
c0=2;
initialLSF=c0*ones(size(Img));
% generate the initial region R0 as a rectangle
initialLSF(1:1080, 1:1920)=-c0;
phi=initialLSF;
figure(1);
mesh(-phi); % for a better view, the LSF is displayed upside down
hold on; contour(phi, [0,0], 'r','LineWidth',2);
title('Initial level set function');
view([-80 35]);
figure(2);
imagesc(Img,[0, 255]); axis off; axis equal; colormap(gray); hold on; contour(phi, [0,0], 'r');
title('Initial zero level contour');
pause(0.5);
potential=2;
if potential ==1
potentialFunction = 'single-well'; % use single well potential p1(s)=0.5*(s-1)^2, which is good for region-based model
elseif potential == 2
potentialFunction = 'double-well'; % use double-well potential in Eq. (16), which is good for both edge and region based models
else
potentialFunction = 'double-well'; % default choice of potential function
end
% start level set evolution
for n=1:iter_outer
phi = drlse_edge(phi, g, lambda, mu, alfa, epsilon, timestep, iter_inner, potentialFunction);
if mod(n,2)==0
figure(2);
imagesc(Img,[0, 255]); axis off; axis equal; colormap(gray); hold on; contour(phi, [0,0], 'r');
end
end
% refine the zero level contour by further level set evolution with alfa=0
alfa=0;
iter_refine = 10;
phi = drlse_edge(phi, g, lambda, mu, alfa, epsilon, timestep, iter_inner, potentialFunction);
finalLSF=phi;
figure(2);
imagesc(Img,[0, 255]); axis off; axis equal; colormap(gray); hold on; contour(phi, [0,0], 'r');
hold on; contour(phi, [0,0], 'r');
str=['Final zero level contour, ', num2str(iter_outer*iter_inner+iter_refine), ' iterations'];
title(str);
pause(1);
figure;
mesh(-finalLSF); % for a better view, the LSF is displayed upside down
hold on; contour(phi, [0,0], 'r','LineWidth',2);
str=['Final level set function, ', num2str(iter_outer*iter_inner+iter_refine), ' iterations'];
title(str);
axis on;
array(i)=finalLSF;
i=i+1;
end
Gives Error:In contour (line 51)
In PE (line 47)
Unable to perform assignment because the left and right sides have a different number of elements.
Error in PE (line 90)
array(i)=finalLSF;

Risposte (1)

dpb
dpb il 22 Dic 2022
array(i)=finalLSF;
tries to stuff the RHS into a single array location where finalLSF was defined as whatever the result of
phi = drlse_edge(phi, g, lambda, mu, alfa, epsilon, timestep, iter_inner, potentialFunction);
finalLSF=phi;
turns out to be. If, as the comments say, that's something that could be displayed meaningfully with countour, then it's obvious it can't be a single number.
It looks like you've lost track of what your variables mean at this point; use the debugger and set a breakpoint and your logic error will likely become obvious.

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by