to draw rectangle containing motion region
Ältere Kommentare anzeigen
I have an image having black background and motion region that is detected is in white color. I want a matlab code to draw the rectangle over image containing all the motion regions. I have tried following code but it is giving wrong output. Plz help me with the code.. {
%for loop to get d first pixel of image having value 255
d=1;
for x=1:1:r
for y=1:1:c
if fd1(x,y)==255 %fd1 is image whose pixels we are checking
as1=x;
bs1=y;
d=0;
break;
end
if (d==0)
break;
end
end
end
}
%reverse for loop to get d last pixel of image having value 255
d=1;
for x=r:-1:1
for y=c:-1:1
if fd1(x,y)==255
ae1=x;
be1=y;
d=0;
break;
end
if(d==0)
break;
end
end
end
w=as1-ae1;
h=be1-bs1;
rectangle('Position',[as1,bs1,w,h],'EdgeColor','g','LineWidth',2)
}
3 Kommentare
David Young
am 22 Mär. 2011
Please could you format the code so it is readable. You can edit your question to do this. Paste the code in again, select it, then click on the {}Code button. Alternatively, indent each line of code by at least two spaces.
Ashish Uthama
am 22 Mär. 2011
+1 on the code format. From your comments, I would suggest looking at the FIND function to replace your loops.
What is 'wrong' about the output?
Karan Ratnaparkhi
am 23 Mär. 2011
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Modify Image Colors finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!