Effacer les filtres
Effacer les filtres

This code divides an image into foreground and background . After that i calculated the threshold value, and varVariance. It gives an error at If varVlues> Th , Cell contents reference from a non-cell array object."

1 vue (au cours des 30 derniers jours)
rgbImage = imread('cameraman.tif');
[r,c]=size(rgbImage);
w = size(rgbImage,1);
h = size(rgbImage,2);
imshow(rgbImage);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
[rows columns numberOfColorBands] = size(rgbImage);
blockSizeR = 40; % Rows in block.
blockSizeC = 40; % Columns in block.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
if numberOfColorBands > 1
ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(rgbImage, blockVectorR, blockVectorC);
end
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
subplot(numPlotsR, numPlotsC, plotIndex);
rgbBlock = ca{r,c};
imshow(rgbBlock); % Could call imshow(ca{r,c}) if you wanted to.
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
drawnow;
plotIndex = plotIndex + 1; end end
meanValues = cellfun(@(x) mean(x(:)),ca);
varValues = cellfun(@(x) var(double(x(:))),ca);
for i=1:numPlotsC+2
varValues1(1,i)=0;
varValues1(numPlotsR+2,i)=0;
end
for i=2 : numPlotsR+2
varValues1(i,1)=0;
varValues1(i,numPlotsC+2)=0;
end
for i=1:numPlotsR
for j=1:numPlotsC
varValues1(i+1,j+1)=varValues(i,j);
end
end
for k = 1 : numPlotsR
for l = 1 : numPlotsC %#ok<ALIGN>
VGx(k,l)=(varValues1(k+2,l+1)-varValues1(k,l+1))/2;
VGy(k,l)=(varValues1(k+1,l+2)-varValues1(k+1,l))/2;
mag(k,l)=sqrt((VGx(k,l).^2)+(VGy(k,l).^2));
s1=.32; s2=.68;
% double LT(k,l);
LT(k,l)=s1*mag(k,l)+s2*varValues(k,l);
Th(k,l)=sqrt(LT(k,l))/meanValues(k,l);
end
end
for i=1:11
for j=1:numPlotsC
if varValues>=Th
ca=varValues(i,j);
end
combine = cell2mat(ca);
end
end
figure,imshow(combine);
  1 commentaire
Sheshjee
Sheshjee le 4 Fév 2013
please help me to suggest me why i am getting this error "Cell contents reference from a non-cell array object."

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 4 Fév 2013
Well the top part looks like my example, but then you did some stuff after that which I don't understand. Originally, ca was a cell array. But you actually redefine ca like this:
ca=varValues(i,j);
for some reason. So now ca is simply a scalar double number, not a cell array anymore. But then immediately afterwards you do this:
combine = cell2mat(ca);
which assumes ca is a cell array. But it's not because you redefined it, so that's why you get the error. But that's about as far as I went because there were no comments to explain what you were doing. All I know is that whatever you're doing, you're doing it incorrectly.

Catégories

En savoir plus sur Red dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by