Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
ezhil K
ezhil K el 6 de Feb. de 2019
Comentada: KSSV el 6 de Feb. de 2019
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');

Respuestas (1)

KSSV
KSSV el 6 de Feb. de 2019
Editada: KSSV el 6 de Feb. de 2019
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 comentarios
ezhil K
ezhil K el 6 de Feb. de 2019
OK.So what should I specify there?
KSSV
KSSV el 6 de Feb. de 2019
Use imcrop and get the both images to the same dimension.....

Iniciar sesión para comentar.

Categorías

Más información sobre Feature Detection and Extraction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by