Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Save Image and Overlay with original image dimensions

Subject: Save Image and Overlay with original image dimensions

From: Eye Lab

Date: 6 Oct, 2008 01:24:02

Message: 1 of 4

I am trying to write some text on 1920x1080 image and then save the image overlaid with text with the same dimensions and no margins. I have tried this:

A = rand(1080,1920);
f = figure('units', 'pixels', 'position', [0 0 1920 1080], 'paperpositionmode', 'auto');
axis off;
image(A);
hold on;
text(100,100,'a',);
set(gca, 'visible', 'off', 'position', [0 0 1920 1080]);
print -dpng test

For some reason this produces a 3843x1610 image

I have also tried saveSameSize.m, but this seems to have a limitation if your screen size is smaller than the image resolution.

Any suggestions?

Thanks!

Subject: Save Image and Overlay with original image dimensions

From: Jan Simon

Date: 6 Oct, 2008 12:02:04

Message: 2 of 4

Hi Eye Lab!

> A = rand(1080,1920);
> f = figure('units', 'pixels', 'position', [0 0 1920 1080], 'paperpositionmode', 'auto');
> axis off;
> image(A);
> hold on;
> text(100,100,'a',);
> set(gca, 'visible', 'off', 'position', [0 0 1920 1080]);
> print -dpng test
>
> For some reason this produces a 3843x1610 image

Does it help to set the axes units to pixels?
  set(gca, 'Units', 'pixels')

Jan

Subject: Save Image and Overlay with original image dimensions

From: Eye Lab

Date: 6 Oct, 2008 23:23:12

Message: 3 of 4

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <gccuns$77p$1@fred.mathworks.com>...
> Hi Eye Lab!
>
> > A = rand(1080,1920);
> > f = figure('units', 'pixels', 'position', [0 0 1920 1080], 'paperpositionmode', 'auto');
> > axis off;
> > image(A);
> > hold on;
> > text(100,100,'a',);
> > set(gca, 'visible', 'off', 'position', [0 0 1920 1080]);
> > print -dpng test
> >
> > For some reason this produces a 3843x1610 image
>
> Does it help to set the axes units to pixels?
> set(gca, 'Units', 'pixels')
>
> Jan

No, that doesn't seem to help. Thanks for the suggestion though.

Subject: Save Image and Overlay with original image dimensions

From: laks gade

Date: 29 May, 2009 23:32:01

Message: 4 of 4

"Eye Lab" <2blka2@gmail.com> wrote in message <gcbpbh$47b$1@fred.mathworks.com>...
> I am trying to write some text on 1920x1080 image and then save the image overlaid with text with the same dimensions and no margins. I have tried this:
>
> A = rand(1080,1920);
> f = figure('units', 'pixels', 'position', [0 0 1920 1080], 'paperpositionmode', 'auto');
> axis off;
> image(A);
> hold on;
> text(100,100,'a',);
> set(gca, 'visible', 'off', 'position', [0 0 1920 1080]);
> print -dpng test
>
> For some reason this produces a 3843x1610 image
>
> I have also tried saveSameSize.m, but this seems to have a limitation if your screen size is smaller than the image resolution.
>
> Any suggestions?
>
> Thanks!


I have been trying to something similar.


spfFig = figure;

colorIm = imread( 'image.png');
imRows = size(colorIm,1); imCols = size(colorIm,2);

figure(spfFig);
reset( gcf ); reset( gca );
set( spfFig , 'Visible', 'off');
imshow( colorIm ); hold on; axis image;
plot( ....// necessary plots and annotations

set( spfFig, 'Units', 'pixels', 'position', [100 100 imCols imRows] );
set( gca, 'Units', 'pixels', 'position', [1 1 imCols imRows ]);
    
set( spfFig, 'paperunits', 'points', 'papersize', [fix((imCols-1)*(3/4))+1 fix((imRows-1)*(3/4))+1]);
set( spfFig, 'paperunits', 'normalized', 'paperposition', [0 0 1 1]);

print( spfFig, sprintf('-r%d', fix(72*(4/3))), '-dpng', sprintf( '%s/%04d.png', spfOutputSeqDir, ind ) );

This is assuming that a pixel unit = 3/4th of a point. This approximation seems to work and the resulting image has the original dimensions without the bordor.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us