warning: Integer operands are required for colon operator when used as index, Please help...its emergency

2 views (last 30 days)
Here are some lines of my code, so as to make it clear
% --- Executes on button press in levelset.
function levelset_Callback(hObject, eventdata, handles)
global img_gray
global Img
global im3
global img
im3=img;
I=img_gray; figure; imshow(I)
title('Select the region of interest from the whole image')
rect = getrect(gcf);
Img = I(rect(2):rect(2)+rect(4),rect(1):rect(1)+rect(3)); %GIVES WARNING
Img=double(Img);
figure(1);
imshow(uint8(Img));
[nx,ny]=size(Img);
ic=floor(nx/2);
jc=floor(ny/2);
r=ic/3;

Accepted Answer

Image Analyst
Image Analyst on 13 Dec 2014
Make it integer like it's asking:
rect = getrect(gcf);
% Might be floating point, so round:
rect = int32(rect);
% Make sure it's never zero because an index of 0 is not allowed.
rect(rect == 0) = 1;
  2 Comments
Image Analyst
Image Analyst on 14 Dec 2014
How abourt using rbbox():
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
p1x = point1(1, 1);
p1y = point1(1, 2);
p2x = point2(1, 1);
p2y = point2(1, 2);
x1 = round(min([p1x, p2x]));
x2 = round(max([p1x, p2x]));
y1 = round(min([p1y, p2y]));
y2 = round(max([p1y, p2y]));
or imrect():
hBox = imrect;
roiPosition = wait(hBox);
roiPosition % Echo coordinates to the command window.
xCoords = [roiPosition(1), roiPosition(1)+roiPosition(3), roiPosition(1)+roiPosition(3), roiPosition(1), roiPosition(1)];
yCoords = [roiPosition(2), roiPosition(2), roiPosition(2)+roiPosition(4), roiPosition(2)+roiPosition(4), roiPosition(2)];
% Plot the mask as an outline over the image.
hold on;
plot(xCoords, yCoords, 'linewidth', 2);

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!