MATLAB: Warning: Integer operands are required for colon operator when used as index, Please help…its emergency

digital image processingimage processingimage segmentation

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;

Best Answer

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;