Shadow detection and removal based on HSV color model.

조회 수: 4 (최근 30일)
Sanjay Saini
Sanjay Saini 2015년 12월 5일
댓글: Karbala'a Unvi. Science 2020년 10월 6일
Index exceeds matrix dimensions.
Error in Bpos (line 37) w= (cfv(i,j)/pv(i,j));
Code is here:
mov = VideoReader('C:/Users/research01/Desktop/Walking.avi');
p=imread('C:/Users/research01/Desktop/1234.png');
p=rgb2hsv(p);
ph=p(:,:,1);
ps=p(:,:,2);
pv=p(:,:,3);
alphaV=0.2;
betaV=0.8;
opFolder = fullfile('F:\imagelab', 'Bpos');
if ~exist(opFolder, 'dir')
mkdir(opFolder);
end
numFrames = mov.NumberOfFrames;
numFramesWritten = 0;
for t = 1 : numFrames
currFrame = read(mov, t);
currFrame=rgb2hsv(currFrame);
figure;imshow(currFrame);
cfh=currFrame(:,:,1);
figure;
imshow(cfh);
cfs=currFrame(:,:,2);
figure;imshow(cfs);
cfv=currFrame(:,:,3);
figure;imshow(cfv);
[m,n]=size(currFrame);
single=zeros(m,n);
for i=1:m
for j=1:n
% a=cfv(i,j);
% progIndication = sprintf('Wrote frame %d.',a);
% disp(progIndication);
w= (cfv(i,j)/pv(i,j));
progIndication = sprintf('Wrote frame %d.',w);
disp(progIndication);
sat=cfs(i,j)-ps(i,j);
progIndication = sprintf('sat frame %d.',w);
disp(progIndication);
hue=cfh(i,j)-ph(i,j);
progIndication = sprintf('hue frame %d.',w);
disp(progIndication);
if(w>=alphaV && w<=betaV && sat<=-0.3 && hue <=0.2)
single(i,j)=1;
else
single(i,j)=0;
end
end
end
imshow(single);
opBaseFileName = sprintf('%3.3d.png', t);
opFullFileName = fullfile(opFolder, opBaseFileName);
imwrite(single, opFullFileName, 'png');
end

채택된 답변

Image Analyst
Image Analyst 2015년 12월 5일
Evidently your still image does not have the same number of rows and columns as your video. You should really check for that before you begin processing. You want to write robust code don't you? Alert your users if that's the case with errordlg().
message = sprintf('Image rows = %d\nImage columns = %d\nVideo rows = %d\nVideo columns = %d',...
rows, columns, videoRows, videoColumns);
uiwait(errordlg(message));
return;
  댓글 수: 2
Image Analyst
Image Analyst 2015년 12월 6일
sanjay, learn how to use the debugger. Or else do it the hard way and put in lines like this:
fprintf('row i=%d, column j=%d\ncfv had %d rows, and %d columns.\npv has %d row and %d columns.\n', ...
i, j, size(cfv, 1), size(cfv, 2), size(pv, 1), size(pv, 2));
Karbala'a Unvi. Science
Karbala'a Unvi. Science 2020년 10월 6일
dear Sir did that solve the problem to you or not?
I need the help too..

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

추가 답변 (1개)

Sanjay Saini
Sanjay Saini 2015년 12월 6일
Dear Image Analyst, As per matlab workspace, i guess both still image and video data has same number of row and columns. As can see in the attached image. Thanks

Community Treasure Hunt

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

Start Hunting!

Translated by