can I store images with differing sizes into a matrix in matrix?

I'm doing object detection and classification to either human or non human from a surveillance video clip. when I detect object and plot it in a rectangular box,I need to save the cropped portion of this object for the purpose of feature extraction and further training the classifier.The problem I encounter is, I'm not able to save the cropped images to a matrix;as it is not copied,I could get only the last cropped image.But I need all the blobs detected. Can anyone please help me to come out of this? Please.... Each cropped image is of different size....

 Accepted Answer

It would be possible to find the problem is your code, when you post the code.
A general method to store arrays of different sizes:
n = 10;
Data = cell(1, n);
for k = 1:n
Data{k} = rand(n, n);
end

3 Comments

source = VideoReader('Z:\\M.Tech\\s3\\NIC\\mfiles\\camclips\\tes.avi'); z=1; cropImgs=cell(:,:,z); for n=1:source.NumberOfFrames bgImg=sprintf('Z:\\minipro\\mog\\pic%d.jpg',n); bgeliminatedImg=imread(bgImg); originalImg=read(source,n); if true % code end % Method for thresholding: using a logical operation. thresholdValue = 100; binaryImage = bgeliminatedImg > thresholdValue; % Bright objects will be the chosen if you use >
% Do a "hole fill" to get rid of any background pixels inside the blobs.
binaryImage = imfill(binaryImage, 'holes');
I=binaryImage;
L = bwlabel(I, 8);
RGB= label2rgb (L, 'hsv', 'k', 'shuffle'); % pseudo random color labels
subplot(2, 2, 1); imagesc(L); title('Labeled Image,bwlabel()'); axis square;hold on;
% Maximize the figure window.
set(gcf, 'Position', get(0, 'ScreenSize'));
subplot(2, 2, 2); imagesc(RGB); title('Conn-components-colored labels,label2rgb()'); axis square;hold on;
blobMeasurements = regionprops(L,bgeliminatedImg, 'all');
numberOfBlobs = size(blobMeasurements, 1);
subplot(2, 2, 3); imagesc(I); title('Outlines, from bwboundaries()'); axis square;
hold on;
boundaries = bwboundaries(I,'noholes');
for k = 1 : numberOfBlobs
% if(blobMeasurements(k).Area>4000) %%to avoid very small connected components
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
% end
end
allBlobAreas = [blobMeasurements.Area];
largeBlobs = find(allBlobAreas > 5000); % Take the larger objects.
% we use ismember to select the blobs that meet our criteria.
newImg = ismember(L, largeBlobs);
maskedImg = bgeliminatedImg; % Simply a copy at first.
maskedImg(~newImg) = 0;% Set all unwanted pixels to zero.
%maskedImg(newImg)=1;
maskedImg=imfill(maskedImg,'holes');
maskedImg=im2bw(maskedImg,0.5);
subplot(2, 2, 4);imagesc(maskedImg);hold on;
title('Original with bounding boxes');
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the mean of each blob.
if(largeBlobs==k)
thisBlobsBox = blobMeasurements(k).BoundingBox; % Get list ofpixels in current blob.
rectangle('Position',thisBlobsBox,'EdgeColor','g');axis square;
CropImgs{z}=imcrop(originalImg,thisBlobsBox);
z=z+1;
end
end
MaskObj(n)=getframe(gcf);
end
The code is nicer, when you format it. Which part of the code concerns your problem? Which variable does not contain the wanted values?
hey....it works...actually,i dnt used CropImgs{z}=imcrop() statement in my code.instead(CropImgs=imcrop())I included it for u...when you replied,I just thought of trying that.... Thanks a lot sir...... Thank you so much.....

Sign in to comment.

More Answers (0)

Asked:

on 5 Mar 2013

Community Treasure Hunt

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

Start Hunting!