What does this error- ''Out of range subscript'' mean during using sub2ind?
古いコメントを表示
Hi! I am working with border irregularity. In my code I had to find out the diagonals of a box. In single code it works but when I used it along other code it shows this error message. I couldn't find the problem.My code is given below:
%read binary mask
mask = imread('image.bmp');
mask=mask(41:616,128:894,1)>128;
%fill all holes:
%flip mask and select everything that is not the outer area
mask= bwlabel(~mask,4) ~= 1;
%find the edge pixels with something like imerode
SE=true(3*ones(1,ndims(mask)));%structuring element
edge= mask & ~( mask & convn(mask,SE,'same')==sum(SE(:)) );
%find the bounding box with 1 px margin
colind_first=find(sum(mask,1),1,'first')-1;
colind_last =find(sum(mask,1),1,'last')+1;
rowind_first=find(sum(mask,2),1,'first')-1;
rowind_last =find(sum(mask,2),1,'last')+1;
box=false(size(mask));
box([rowind_first rowind_last], colind_first:colind_last )=true;
box( rowind_first:rowind_last ,[colind_first colind_last])=true;
%add the diagonal lines to the box
x=false(size(mask));
p=polyfit([rowind_first rowind_last],[colind_first colind_last],1);
row=rowind_first:rowind_last;
col=round(polyval(p,row));
x(sub2ind(size(x),row,col))=true;
%add other diagonal to x
p=polyfit([rowind_first rowind_last],[colind_last colind_first],1);
col=round(polyval(p,row));
x(sub2ind(size(x),row,col))=true;
In my main code I had to delete this line so I can't understand if it causes the problem:
mask=mask(41:616,128:894,1)>128;
where ''mask'' is the segmented image.The image is:

11 件のコメント
madhan ravi
2020 年 6 月 16 日
Without mask how can we run the code? Upload it as .mat file.
KSSV
2020 年 6 月 16 日
check size(z) and (roww,coll) it looks like your row and col indices are higher than the size of z.
joynob ahmed
2020 年 6 月 16 日
KSSV
2020 年 6 月 16 日
What you wanted to do with this line?
mask=mask(41:616,128:894,1)>128;
joynob ahmed
2020 年 6 月 16 日
編集済み: joynob ahmed
2020 年 6 月 17 日
Mohammad Sami
2020 年 6 月 16 日
Can you investigate the output col value here, it maybe outside the range of your data, causing this error.
col=round(polyval(p,row));
Rik
2020 年 6 月 16 日
You still haven't removed the white border around your image. Because you insisted it wasn't there, I simply used this line of code to remove it to get to the point you claimed to be.
You need to have a binary image without a white border after that line of code. How you achieve that is up to you.
joynob ahmed
2020 年 6 月 17 日
編集済み: joynob ahmed
2020 年 6 月 17 日
joynob ahmed
2020 年 6 月 18 日
KSSV
2020 年 6 月 18 日
What exactly is your problem? You want diagonals of the bounding box of the irregular domain i.e white region in the image?
joynob ahmed
2020 年 6 月 18 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!