Is it possible to read in an input image, add an overlay and then output the result so that it is exactly the same size in MATLAB 7.6 (R2008a)?

1 view (last 30 days)
I was looking through the documentation on how to perform this but was unable to find an example or a straightforward procedure.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
A description of how to perform an operation like this does not exist in the documentation. Although it is a common operation, performing it is non-trivial. Here is a method on how to do this using figures and PRINT.
function plotimage ()
im = imread ('input.jpg'); % read input file
fig = figure;
[x y colors]=size(im); %get position data
set (gcf, 'PaperUnits', 'normalized');
set (gcf, 'PaperPosition', [0 0 1 1]);
set (gcf, 'PaperSize', [1 1]);
set (gcf, 'PaperPositionMode', 'auto');
warning ('off', 'Images:initSize:adjustingMag');
imshow (im, 'Border', 'tight', 'InitialMagnification', 100);
set (gcf, 'units','pixels');
set (gcf, 'position', [1 1 y x]);
hold on;
plot (100, 100, 'g+');
print ('-djpeg', 'output.jpg', '-r0');
close (fig);
end
Below is a much simpler method of performing the same operation using IMWRITE and IMREAD.
function plotimage_imwrite ()
im = imread ('input.jpg'); %read input file
fig = figure;
%Note that IMSHOW is part of IPT.
imshow (im, 'Border', 'tight', 'InitialMagnification', 100);
hold on;
plot (1:10:100, 1:10:100, 'g+');
F = getframe (gcf); % capture frame
imwrite (F.cdata,'output.jpg','jpg','Quality',100); % write image to file
close (fig);
end

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!