Error using lazysnapping,Expected input number 3, foreground, to be integer-valued.

10 ビュー (過去 30 日間)
cui,xingxing
cui,xingxing 2020 年 11 月 12 日
回答済み: cui,xingxing 2020 年 11 月 12 日
Why is there a problem with the third input parameter of "lazysnapping"? I think it is an integer value.
RGB = imread('peppers.png');
L = superpixels(RGB,500); % 分块,主要是加速图像处理
[h,w,c] = size(RGB);
% figure
% BW = boundarymask(L);
% imshow(imoverlay(RGB,BW,'cyan'),'InitialMagnification',67)
figure
imshow(RGB)
h1 = drawpolyline('Color','green'); % 代表前景
roiPoints1 = h1.Position;
h2 = drawpolyline('Color','blue');%代表背景
roiPoints2 = h2.Position;
foregroundInd = sub2ind([h,w],roiPoints1(:,2),roiPoints1(:,1));
backgroundInd = sub2ind([h,w],roiPoints2(:,2),roiPoints2(:,1));
% roi = zeros(size(RGB,1),size(RGB,2),'uint8');
% roi(roiPoints1(:,2),roiPoints1(:,1)) = 255;
BW = lazysnapping(RGB,L,foregroundInd,backgroundInd);
% BW = grabcut(RGB,L,roi);
figure
imshow(BW)
maskedImage = RGB;
maskedImage(repmat(~BW,[1 1 3])) = 0;
figure;
imshow(maskedImage)
Error using lazysnapping
Expected input number 3, foreground, to be integer-valued.
Error in lazysnapping>validateInputs (line 248)
validateattributes(foreground,validMaskTypes,{'nonnan','nonsparse', ...
Error in lazysnapping (line 158)
[foregroundInd,backgroundInd,is3D] = validateInputs(A,L,foreground,background);
Error in faceCropID (line 20)
BW = lazysnapping(RGB,L,foregroundInd,backgroundInd);

採用された回答

cui,xingxing
cui,xingxing 2020 年 11 月 12 日
I have found the problem, "position" is a decimal, it needs to be an integer.
roiPoints1 = floor(h1.Position);
roiPoints2 = floor(h2.Position);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by