how to fix Attempt to grow array along ambiguous dimension-Error?

I am trying to draw rectangle around the region where there are only the characters and numbers.But I'm getting error.I have attached the code and the error.please help mein rectifying it.
Error is:
Attempt to grow array along ambiguous dimension.
Error in tes (line 33)
redChan(perim) = 255;test3.png
% Clear all varibles and close all windows
clear all;
close all;
% Read in image
imorig = imread('test3.png');
% Threshold and invert
im = ~im2bw(imorig);
% Find bounding boxes of all characters
s = regionprops(im, 'BoundingBox');
bbox = round(reshape([s.BoundingBox], 4, []).');
% Create a blank image and for each box, fill in with white
outImg = false(size(im));
for idx = 1 : size(bbox,1)
outImg(bbox(idx,2):bbox(idx,2)+bbox(idx,4), ...
bbox(idx,1):bbox(idx,1)+bbox(idx,3)) = true;
end
% Close with a very large structuring element
se = strel('square', 20);
outImg2 = imclose(outImg, se);
% Find the perimeter of this object, then take the original image and
% the pixels that belong to this boundary. Colour all of these pixels red
% for illustration
redChan = imorig(:,:,1);
greenChan = imorig(:,:,2);
blueChan = imorig(:,:,3);
perim = bwperim(outImg2,8);
redChan(perim) = 255;
greenChan(perim) = 0;
blueChan(perim) = 0;
out = cat(3,redChan,greenChan,blueChan);
figure;
subplot(1,2,1);
imshow(imorig);
title('Original image');
subplot(1,2,2);
imshow(out);
title('Image with perimeter overlaid');

Answers (1)

Check the sizes of perim and redChan . They are
perim 220x684 150480 logical
redChan 219x683 149577 uint8
When you use :
redChan(perim) = 255;
YOu are trying to extract more number of dimensions, then existing. So the error. YOu need to do proper intiailizations.

2 Comments

OK.So what should I specify there?
Use imcrop and get the both images to the same dimension.....

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Asked:

on 6 Feb 2019

Commented:

on 6 Feb 2019

Community Treasure Hunt

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

Start Hunting!