필터 지우기
필터 지우기

Applying free hand crop to TWO images simultaneously

조회 수: 2 (최근 30일)
Jane
Jane 2014년 1월 11일
댓글: Jane 2014년 1월 11일
Hello, I have two nearly identical images and I'd like to use imfreehand on ONE of the images, but save the boundaries of the drawn freehand on BOTH images to crop and save this section on BOTH images.
Here's a screen cap of what I have so far
Can you please help with this code? Code adapted from Image Analyst.
% Read image file
grayImage = imread(rotlegsegmentFilename);
grayImageFluor = imread(rotlegsegmentFilenameFluor);
subplot(1,2,1)
imshow(grayImageFluor, []);
subplot(1,2,2)
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand();
%
% Create a binary image ("mask")
binaryImage = hFH.createMask();
xy = hFH.getPosition;
%
% Get coordinates of the boundary of the freehand drawn region.
structBoundaries = bwboundaries(binaryImage);
xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates.
x = xy(:, 2); % Columns.
y = xy(:, 1); % Rows.
drawnow; % Force it to draw immediately.
%
% Will keep only the part of the image that's inside the mask, zero outside mask.
blackMaskedImage = grayImage;
blackMaskedImage(~binaryImage) = 0;
%
% Crop the image.
leftColumn = min(x);
rightColumn = max(x);
topLine = min(y);
bottomLine = max(y);
width = rightColumn - leftColumn + 1;
height = bottomLine - topLine + 1;
cropImage = imcrop(blackMaskedImage, [leftColumn, topLine, width, height]);
Many thanks!

채택된 답변

Image Analyst
Image Analyst 2014년 1월 11일
You forgot to attach your images. So what's the problem? Just call imcrop() on each image.
  댓글 수: 1
Jane
Jane 2014년 1월 11일
Sorry, you're right! I got it - thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by