Tracking error
Show older comments
Hi everyone, can you please help me to solve the error? when I implement this code, it show me the error with this.
>>??? Error using ==> times
>>Number of array dimensions must match for binary array op.
>>Error in ==> colorTracking2 at 204
>> maskImageR = closedilate3.* org_pixels(:,:,1,b);
Code:
avi = aviread('barbeq');
fileinfo=aviinfo('barbeq');
numberOfFrames=100;
org_pixels = double(cat(4,avi(1:numberOfFrames).cdata))/255;
% frame rate of the video...
fps=fileinfo.FramesPerSecond;
% number of frames of the video
nFrames = size(org_pixels,4);
% Ask user if they want to write the individual frames out to disk.
promptMessage = sprintf('Do you want to save the individual frames out to individual disk files?');
button = questdlg(promptMessage, 'Save individual frames?', 'Yes', 'No', 'Yes');
if strcmp(button, 'Yes')
writeToDisk = true;
% Extract out the various parts of the filename.
[folder, baseFileName, extentions] = fileparts(movieFullFileName);
% Make up a special new output subfolder for all the separate
% movie frames that we're going to extract and save to disk.
% (Don't worry - windows can handle forward slashes in the folder name.)
folder = pwd; % Make it a subfolder of the folder where this m-file lives.
outputFolder = sprintf('%s/Movie Frames from %s', folder, baseFileName);
% Create the folder if it doesn't exist already.
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
else
writeToDisk = false;
end
% the file that will be generated to store the detected fire in the video
f_out='barbeq1.avi';
% you can change Indeo3 with none
%fire_avi = avifile('barbeq1', 'compression', 'none' , 'fps',...
% fileinfo.FramesPerSecond);
%- convert the coloured image into gray image
for f = 1:nFrames
pixels(:,:,f) = (rgb2gray(org_pixels(:,:,:,f)));
end
%size(org_pixels);
[row1,column1,t]=size(pixels);
scrsz = get(0,'ScreenSize');
figure('Position',[20 scrsz(4)/2 scrsz(3) scrsz(4)/3]);
hold on;
ax(1)=subplot(3,4,1); axis tight;
ax(2)=subplot(3,4,2); axis tight;
ax(3)=subplot(3,4,3); axis tight;
ax(4)=subplot(3,4,4); axis tight;
ax(5)=subplot(3,4,5); axis tight;
ax(6)=subplot(3,4,6); axis tight;
ax(7)=subplot(3,4,7); axis tight;
ax(8)=subplot(3,4,8); axis tight;
ax(9)=subplot(3,4,9); axis tight;
linkaxes(ax,'xy');
set(ax,'XAxisLocation','bottom','XDir','normal','YDir','reverse',...
'XGrid','ON','YGrid','ON', 'XTick',0:50:column1,'YTick', ...
0:50:row1, 'XLim',[0,column1],'YLim',[0,row1],'TickDir','out');
% pause(pauseDur);
pause;
for b = 2:nFrames
subplot(ax(1));
hold on;
% display the frame
image(org_pixels(:,:,:,b));
title(['original frame ',num2str(b)]);
% pause(pauseDur);
pause;
% display the difference
d(:,:,b)=(imabsdiff(pixels(:,:,b),pixels(:,:,b-1)));
k=d(:,:,b);
subplot(ax(2)); %axes(ax(3)); %ax2
disp('display the difference between 2 frames...');
imshow(k);title('difference between 2 frames ');
% pause(pauseDur);
pause;
%= binThreshold =0.2 for instance....
binThreshold = 0.3;
bw(:,:,b) = im2bw(k, binThreshold);
kk=bw(:,:,b);
%size(kk)
% Labelling
bw1=bwlabel(kk);
disp('labelling...');
subplot(ax(3)); %ax3
hold on;
colormap('gray');
image(bw1);title(' labelled Image ');
disp(' labelling was completed...');
% pause(pauseDur);
pause;
% filtering....erosion and dilation
se = strel('diamond', 3);
dilate1 = imdilate(k, se);
edge1 = edge(dilate1, 'canny', 0.78, 0.9);
dilate2 = imdilate(edge1, se);
closedilate2 = imclose(dilate2, se);
disp('erosion and dilation done ');
hold on;
subplot(ax(4)); %ax4
imshow(closedilate2);title('ErrodedDilated image...');
% pause(pauseDur);
pause;
% substract the fire from the original frame
% Get the 3 components: Red, Green, Blue...
outputImg_R=closedilate2.*org_pixels(:,:,1,b);
outputImg_G=closedilate2.*org_pixels(:,:,2,b);
outputImg_B=closedilate2.*org_pixels(:,:,3,b);
% form the colour image from the Red,Green,Blue components
outputImg=cat(3,outputImg_R,outputImg_G,outputImg_B);
disp('fire image detected....');
%subplot(ax(2)); % ax 5
subplot(ax(5));
image(outputImg);title('fire region image...');
% pause(pauseDur);
pause;
%fire_avi = close(fire_avi);
redThresholdLow = 0.55;
redThresholdHigh = 50;
greenThresholdLow = 0.1;
greenThresholdHigh = 50;
blueThresholdLow = 0.859;
blueThresholdHigh = 50;
% smallestAcceptableArea = 100;
redMask = (org_pixels(:,:,1,b) >= redThresholdLow) & (org_pixels(:,:,1,b) <= redThresholdHigh);
greenMask = (org_pixels(:,:,2,b) >= greenThresholdLow) & (org_pixels(:,:,2,b) <= greenThresholdHigh);
blueMask = (org_pixels(:,:,3,b) >= blueThresholdLow) & (org_pixels(:,:,3,b) <= blueThresholdHigh);
redObjectsMask = uint8(redMask & greenMask & blueMask);
ce = strel('diamond', 3);
dilate1co = imdilate(redObjectsMask, ce);
edge1co = edge(dilate1co, 'canny', 0.78, 0.9);
dilate2co = imdilate(edge1co, se);
closecolordilate = imclose(dilate2co, se);
% subplot(ax(4)); %ax6
subplot(ax(6));
imshow(closecolordilate, []);title('color region image...');
pause;
maskedImageR = closecolordilate .* org_pixels(:,:,1,b);
maskedImageG = closecolordilate .* org_pixels(:,:,2,b);
maskedImageB = closecolordilate .* org_pixels(:,:,3,b);
maskedRGBImage = cat(3, maskedImageR, maskedImageG, maskedImageB);
%disp(outputImg)
pause
disp('color image detected....');
%subplot(ax(5)); %ax7
subplot(ax(7));
image(maskedRGBImage); title('frames color region image...');
pause;
% combine all motion and color tracking image from original avi file.
subplot(ax(8));
frametrack = (maskedRGBImage)&(outputImg);
image(frametrack); title('fire tracking')
se3 = strel('diamond', 3);
dilate3 = imdilate( frametrack , se3);
closedilate3 = imclose(dilate3, se3);
% pause
%subplot(ax(9));
maskImageR = closedilate3.* org_pixels(:,:,1,b);
maskImageG = closedilate3.* org_pixels(:,:,2,b);
maskImageB = closedilate3.* org_pixels(:,:,3,b);
maskRGBImage = unit8(3, maskImageR, maskImageG, maskImageB);
subplot(ax(9));
disp(maskImageR)
end
end
2 Comments
Ernest
on 30 May 2012
Oleg Komarov
on 30 May 2012
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
Answers (1)
Walter Roberson
on 30 May 2012
1 vote
Your code constructs closedilate3 as a three dimensional array (RGB), but org_pixels(:,:,1,b) is only going to be a 2 dimensional array, leading to your problem.
You should either be multiplying a 3D array by a 3D array, or a 2D array by a 2D array.
Categories
Find more on Morphological Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!