2016-12-19 13 views
0

정확한 호출로 인한 ROI를 저장하는 방법에 대해 혼란 스럽습니다.Matlab : 이미지 결과 저장 방법 IMRECT로 선택한 ROI의 실시간 플로팅

function Zoomer 
figure(); 

highResImage = imread('E:\My Work\THESISQ\FIX\Koding\data coba\Image_3060.jpg'); 
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 

이 내 사진을 내가 그 코드

Picture of cells with one lymphocyte cell

을 사용하여이 그림에서 림프구 세포를 자르려 : 나는 subplot(2,1,2)

코드에 이미지를 저장하고 싶은 것은 코드를 실행 한 후 결과는

the result image

입니다.

subplot(2,1,2)에 이미지를 저장하려면 어떻게해야합니까?

+0

코드 스크린 샷을 게시하지 마십시오. 이미지는 검색 할 수 없으며 테스트를 위해 복사 할 수 없으며 접근성을 방해합니다. 대신 관련 코드를 [형식화 된 텍스트]로 포함하십시오 (http://stackoverflow.com/help/formatting). – Meyer

+0

귀하의 조언을 주셔서 감사합니다 @ 마이어 –

+0

응? 'highResThumbnail'을 어떻게 저장할까요? save myfile.mat highResThumbnail'? –

답변

0

편집 : 당신이 이미 성공적으로 추출 및 디스플레이 highResThumbnail 때문에 imrect에서 좌표를 사용하여 이미지에서 부분 행렬을 추출하는 방법을 알고 같은 내가 처음에 너무 빨리 당신의 질문을 읽고, 그것을 보인다. 누락 된 유일한 부분은 행렬을 이미지로 저장하는 방법입니다. 지원되는 이미지 형식 예를 들어

highResThumbnail을 저장

사용 imwrite 이미지

imrect 명령의 조각을 얻을 수 imrect를 사용하는 방법


imwrite(highResThumbnail, 'thumb.png'); 
단지 x와 y 좌표와 너비와 높이를 제공합니다. 선택한 직사각형을 저장합니다. 좌표를 사용하여 이미지 행렬에 색인을 붙이십시오. 그런 다음 서브 매트릭스를 imwrite으로 저장할 수 있습니다.

A = imread('peppers.png'); 
figure, imshow(A); 
h = imrect; 
position = wait(h); %Pause until user double clicks on rectangle 

%position contains [x y width height] 
startx = position(1); 
endx = position(1)+position(3); 
starty = position(2); 
endy = position(2)+position(4); 

%Use the coordinates to grab a submatrix of A 
B = A(starty:endy, startx:endx, :); 
imwrite(B, 'pepper_rect.png'); 

서브 플로트의 경우 활성 서브 플로트에서만 사각형을 선택할 수 있습니다. subplot 명령을 다시 호출하여 하위 그림간에 전환 할 수 있습니다.

%Plot all my images 
figure; 
subplot(2,1,1); 
imshow('peppers.png'); 

subplot(2,1,2); 
imshow('saturn.png'); 

%Active image is the most recently plotted 
h = imrect; 
position = wait(h); %Pause until user double clicks on rectangle 

%Call subplot again to activate first image 
subplot(2,1,1); 
h = imrect; 
position = wait(h); %Pause until user double clicks on rectangle 
+0

코드를 사용해 보았는데 너는 제안한다. 나는 B = imcrop A를 추가했다. (starty : endy, startx : endx, :); 하지만 사진을 자르지 못했습니다. 뭔가 놓쳤습니까? 아니면 잘못 되었나요? 세실리아를 바로 잡으십시오. 고맙습니다. –

+0

['imcrop'] (https://www.mathworks.com/help/images/ref/imcrop.html)을 사용하지 말고 게시 한 원본 코드에서 사용하지 않았습니다. 뭔가 새로운 것을 시도하고 있습니까? 'imcrop'을 사용하면 예제 코드의 "highresthumbnail"행렬이나 예제 코드의 B 행렬을 생성하는 대신에 imrect를 사용할 수 있습니다. 그러나 여러분은 이미 그 코드를 가지고 있기 때문에 왜 필요하다고 생각하는지 모르겠습니다. . – Cecilia