Union of an image

3 views (last 30 days)
Marcus
Marcus on 20 Dec 2012
Hi Guys
I am new to matlab and I am currently doing a project to distinguish between a photo taken by an amateur photographer and a professional photographer.
How do union or overlap an image over another?
I have to use the combined image to compare with a test image using Scale-Invariant Feature Transform. I sincerely appreciate anyone who is able to help me.
Thanks
Marcus
  4 Comments
Marcus
Marcus on 20 Dec 2012
Not stitching. Combining two images into one (not side by side and not one on top one at the bottom)
Jan
Jan on 20 Dec 2012
@Walter: I assume he wants an image registration.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 20 Dec 2012
Why not just make up your test images in Photoshop or Gimp? Photo-retouching and compositing are what those programs are made for. It's a lot more tedious and less flexible in MATLAB whereas it's interactive and highly visual in Photoshop. You can use masks and feather and anti-alias seams, etc. MATLAB can do it by indexing but it's not very interactive and will have a lot more edge artifacts - it's just not made for that sort of interactive activity.
  10 Comments
Marcus
Marcus on 21 Dec 2012
yes but can u provide a reference code with image2(row1:row2, col1:col2) = imageToPutIn; used so I can try it out? Thanks a lot!
Image Analyst
Image Analyst on 21 Dec 2012
If your answer is solved, then go ahead and mark it as such.
clear
clc;
close all;
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'Moon.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
bigGrayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(bigGrayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(bigGrayImage, []);
title('Original BIG Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% 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
smallGrayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[smallRows smallColumns numberOfColorBands] = size(smallGrayImage);
% Display the original gray scale image.
subplot(2, 2, 2);
imshow(smallGrayImage, []);
title('Original SMALL Grayscale Image', 'FontSize', fontSize);
% Note: smallGrayImage could just have well been a sub-portion of
% another image that you extracted out with imcrop() or indexing.
% Paste small image into big one.
% Put upper left at xColumn = 50, and yRow = 100.
xColumn = 50;
yRow = 100;
row1 = yRow;
row2 = row1 + smallRows - 1;
col1 = xColumn;
col2 = col1 + smallColumns - 1;
% Not shown: making sure they don't exceed
% image boundaries and making adjustments if they do.
pastedImage = bigGrayImage; % Initialize.
pastedImage(row1:row2, col1:col2) = smallGrayImage;
% Display the pasted gray scale image.
subplot(2, 2, 3);
imshow(pastedImage, []);
title('Pasted Image', 'FontSize', fontSize);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!