Hello all,
I am quite beginner for matlab coding. I have a code which selects a ROI over an image. You may find code below.
clear allclcrandomimage=randi([0 2^16-1], 256, 256, 'uint16');%imshow(randomimage)
S = [64 64 127 127]; figure, imshow(randomimage);h = imrect(gca, S); addNewPositionCallback(h,@(p) title(mat2str(p,3)));fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));setPositionConstraintFcn(h,fcn)position = wait(h); ROIIMAGE = imcrop(randomimage,position);close allfigure, imshow(ROIIMAGE);
Code generates a random 16 bit image and create a size adjustable rectangular to select ROI. Then selected ROI will be opened as another figure by double clicking the rectangle.
My question is how can I put this code into a function. Thanks in advance.
Best Answer