Applying free hand crop to TWO images simultaneously
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Image Analyst
2014 年 1 月 11 日
You forgot to attach your images. So what's the problem? Just call imcrop() on each image.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!