Effacer les filtres
Effacer les filtres

Applying free hand crop to TWO images simultaneously

2 vues (au cours des 30 derniers jours)
Jane
Jane le 11 Jan 2014
Commenté : Jane le 11 Jan 2014
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!

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by