필터 지우기
필터 지우기

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 (최근 30일)
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
Sheshjee
Sheshjee 2013년 2월 4일
please help me to suggest me why i am getting this error "Cell contents reference from a non-cell array object."

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2013년 2월 4일
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.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by