필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
ezhil K
ezhil K 2019년 2월 6일
댓글: KSSV 2019년 2월 6일
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');

답변 (1개)

KSSV
KSSV 2019년 2월 6일
편집: KSSV 2019년 2월 6일
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
ezhil K
ezhil K 2019년 2월 6일
OK.So what should I specify there?
KSSV
KSSV 2019년 2월 6일
Use imcrop and get the both images to the same dimension.....

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by