일반적으로 imrect
에 콜백을 지정해야합니다. 예 :
x = imrect();
x.addNewPositionCallback(@(x)(disp('The rect has changed')))
익명 함수를 사용하여 이미지와 두 번째 축과 같은 추가 매개 변수를 콜백에 가져와야합니다.
내가 원하는 것을 수행하는 작은 코드 스 니펫을 작성했습니다. 귀찮게하지 않았으므로 경계 체크를 추가해야합니다. 사각형을 이동할 때 imshow
을 실행하는 대신 CData
을 업데이트하므로 매우 부드럽습니다. 세 차이 안드레이의 답변 @로
는
function Zoomer
figure();
highResImage = imread('peppers.png');
lowResImage = imresize(highResImage,0.5);
a1 = subplot(2,1,1);
a2 = subplot(2,1,2);
imshow(lowResImage,'Parent',a1);
initialPosition = [10 10 100 100];
lowResRect = imrect(a1,initialPosition);
lowResRect.addNewPositionCallback(@(pos)Callback(pos,a2,highResImage));
Callback(initialPosition , a2, highResImage);
end
function Callback(position,axesHandle, highResImage)
position = position * 2;
x1 = position(1);
y1 = position(2);
x2 = position(1) + position(3);
y2 = position(2) + position(4);
highResThumbnail = highResImage(round(y1:y2),round(x1:x2),:);
if isempty(get(axesHandle,'Children'))
imshow(highResThumbnail,'Parent',axesHandle);
else
imHandle = get(axesHandle,'Children');
oldSize = size(get(imHandle,'CData'));
if ~isequal(oldSize, size(highResThumbnail))
imshow(highResThumbnail,'Parent',axesHandle);
else
set(imHandle,'CData', highResThumbnail);
end
end
end
하는 체크 아웃 : http://stackoverflow.com/questions/10998739/scaleable-dragable-box-on-plots-that-select-select-data/10998803 # 10998803 –