how to fix Attempt to grow array along ambiguous dimension-Error?
조회 수: 1 (최근 30일)
이전 댓글 표시
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202909/test3.png)
![test3.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202909/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');
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Display and Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!