how can i recombine image after i separated it?

1 view (last 30 days)
how can i recombine an image after i used imfreehand function to separate region of interisted and then i processed region of non interest, now i want to combine region of interst with region of non interest. any help is apprecited.

Answers (2)

Walter Roberson
Walter Roberson on 28 Dec 2012
Copy the old image to a new array, and copy the roi points in the processed image on top of the roi points in the new array.

Image Analyst
Image Analyst on 28 Dec 2012
You mean like this demo:
% Demo to have the user freehand draw an irregular shape over
% a gray scale image, have it save that part, blur the image,
% and to write the saved pixels over the blurred image.
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
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") from the ROI object.
binaryImage = hFH.createMask();
xy = hFH.getPosition;
% Save the original pixels in the mask
savedPixels = grayImage(binaryImage);
% Now make it smaller so we can show more images.
subplot(2, 3, 1);
imshow(grayImage, []);
axis on;
drawnow;
title('Original Grayscale Image', 'FontSize', fontSize);
% Display the freehand mask.
subplot(2, 3, 2);
imshow(binaryImage);
axis on;
title('Binary mask of the region', 'FontSize', fontSize);
% Mask the image and display it.
% Will keep only the part of the image that's inside the mask, zero outside mask.
blackMaskedImage = grayImage;
blackMaskedImage(~binaryImage) = 0;
subplot(2, 3, 3);
imshow(blackMaskedImage);
axis on;
title('Masked Outside Region', 'FontSize', fontSize);
% Now blur the image
windowWidth = 21;
blurredImage = conv2(grayImage, ones(windowWidth)/windowWidth^2, 'same');
subplot(2, 3, 4);
imshow(blurredImage, []);
title('Blurred image', 'FontSize', fontSize);
% Now replace the pixels with the original pixels
blurredImage(binaryImage) = savedPixels;
subplot(2, 3, 5);
imshow(blurredImage, []);
title('Blurred image plus original saved pixels', 'FontSize', fontSize);

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!