フィルターのクリア

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