Yumnam Kirani Singh
Tronglaobi Awang Leikai
"meena rao" <meen...@yahoo.co.in> wrote in message <ies80t$ph9$1...@fred.mathworks.com>...
-------------------------------------------------------
To *draw* it you can use the line() or plot() function. You of course
have to know the coordinates of the bounding rows and columns. If you
don't know that then you have to do some image segmentation, namely
using regionprops to get the BoundingBox property of the object.
See my BlobsDemo for an example of image segmentation and cropping out
of the image the various objects inside their bounding boxes:
http://www.mathworks.com/matlabcentral/fileexchange/25157
ImageAnalyst <imagea...@mailinator.com> wrote in message <23a83424-16ca-4715...@s4g2000yql.googlegroups.com>...
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos';
baseFileName = 'coins.png';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Binarize the image.
binaryImage = grayImage > 100;
% Display the image.
subplot(2, 2, 3);
binaryImage = imfill(binaryImage, 'holes');
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Label each blob so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'BoundingBox',
'Area');
allBlobAreas = [blobMeasurements.Area];
% Display the original gray scale image.
subplot(2, 2, 4);
imshow(grayImage, []);
title('Original Grayscale Image with Bounding Boxes', 'FontSize',
fontSize);
% Loop through all blobs, putting up Bounding Box.
hold on; % Prevent boxes from blowing away the image and prior boxes.
for k = 1 : numberOfBlobs
boundingBox = blobMeasurements(k).BoundingBox; % Get box.
x1 = boundingBox(1);
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
% Calculate width/height ratio.
aspectRatio(k) = boundingBox(3) / boundingBox(4);
fprintf('For blob #%d, area = %d, aspect ratio = %.2f\n', ...
k, allBlobAreas(k), aspectRatio(k));
% Plot the box in the overlay.
plot(verticesX, verticesY, 'r-', 'LineWidth', 2);
end
msgbox('Done with demo. See command window for areas and aspect
ratios.');
ImageAnalyst <imagea...@mailinator.com> wrote in message <9e8438b3-e6bd-43f1...@w2g2000yqb.googlegroups.com>...
I've try this code. How I want to know height of object???
So, that's mean width for the object is BoundingBox(3)? Is it true?
I wrote this code on a foreground separated video (separated foreground using mixture of Gaussian method) and I intend to plot the centroid and bounding box,velocity of the moving object in the video( velocity of one connected component = distance(connected component in second frame,connected component in first frame)/fps.)Though I have not written the code for displaying velocity on the image.I wrote the code for bounding box and centroid.Please have a look at this and the video which I have is 100 frames.
clear all
close all
clc
tic
disp('Execution Started')
vidobj = VideoReader('mixture_of_gaussians_output1.avi');
NumFrames = vidobj.NumberOfFrames;
frames = cell(1,NumFrames);
bwframe = cell(1,NumFrames);
cc = cell(1,NumFrames);
for m=1:NumFrames
frames{m} = rgb2gray(read(vidobj,m));
end
[r c] = size(frames{20});
for m = 1:NumFrames
level = max(frames{m}(:));
for n = 1:r
for o = 1:c
if frames{m}(n,o)> level-10 && frames{m}(n,o) <= level+10
frames{m}(n,o) = 255;
else
frames{m}(n,o) = 0;
end
end
end
bwframe{m} = frames{m};
end
figure,
for m=1:NumFrames
imshow(bwframe{m})
hold on
aropn{m} = bwareaopen(bwframe{m},15);
bw{m} = bwconncomp(aropn{m},8);
stats{m} = regionprops(bw{m},'BoundingBox','Centroid');
for object = 1:length(stats{m})-1
bb = stats{m}(object).BoundingBox;
bco = stats{m}(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bco(1),bco(2),'-m+')
a = text(bco(1)+15,bco(2),strcat('X: ',num2str(round(bco(1))),' Y: ',num2str(round(bco(2)))));
set(a,'FontName','Arial','FontWeight','normal','FontSize',12,'Color','blue');
ha = gca;
set(ha,'xdir','normal')
set(ha,'ydir','reverse')
set(ha,'xlim',[1 c])
set(ha,'ylim',[1 r])
grid on
end
end
hold off
toc
disp('Execution Ended')
So I would like to plot the image frame first then the bounding box and the value of the centroid (and velocity of the object in the future) and the user who executes my code should be able to see this as a video (earlier I have used im2frame to convert image into video so intially I want to plot image,bounding box and centroid all together)
Kindly help me out,
-Harsha
---------------------------------------------------------------------------------
And where did you upload "'mixture_of_gaussians_output1.avi"?
By the way, you should have started your own thread rather than add on
to someone else's unrelated thread. Do that for your response.