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:
Write data on picture files.

Subject: Write data on picture files.

From: Pascal Steiss

Date: 2 Jul, 2009 10:45:07

Message: 1 of 2

Dear community

I rendered some scientific stuff.
Now I want to put the parameters on the frames.
I thought of using Matlab.

-- snip --
fileNamePrefix = 'SplitRecombMovie0';
for i=660:700
    fileName = [fileNamePrefix, num2str(i), '.bmp'];
    image = imread(fileName);
    imagesc(image);

    set(gca,'DataAspectRatio', [1,1,1],'PlotBoxAspectRatio',[1 1 1])
    set(gca, 'Box', 'off', 'GridLineStyle', 'none', 'XGrid', 'off',
'XTick', [], 'YTick', []);
    
    text('String', ['P_{mw}=', num2str((i-660)*120/(831-660),3), ' mW'],
'Position', [600, 80], 'Color', 'white', 'FontSize', 15);
   f = getframe(gca);
   imwrite(f.cdata, [num2str(i), '.bmp']);
end;
-- snap --

Now my problem: The original files have a size of 800 x 600 pixels.

What I get with imwrite does not have 800x600 Pixels.
How do I tell the axes object to have exactly an extend of 800 x 600
pixels on my screen so that imwrite produces figures of 800x600 px?

Thank you
Pascal

Subject: Write data on picture files.

From: Ashish Uthama

Date: 2 Jul, 2009 19:01:36

Message: 2 of 2

On Thu, 02 Jul 2009 06:45:07 -0400, Pascal Steiss
<_NO-SPAM_pascal.steiss@gmx.ch> wrote:

> Dear community
>
> I rendered some scientific stuff.
> Now I want to put the parameters on the frames.
> I thought of using Matlab.
>
> -- snip --
> fileNamePrefix = 'SplitRecombMovie0';
> for i=660:700
> fileName = [fileNamePrefix, num2str(i), '.bmp'];
> image = imread(fileName);
> imagesc(image);
>
> set(gca,'DataAspectRatio', [1,1,1],'PlotBoxAspectRatio',[1 1 1])
> set(gca, 'Box', 'off', 'GridLineStyle', 'none', 'XGrid', 'off',
> 'XTick', [], 'YTick', []);
> text('String', ['P_{mw}=', num2str((i-660)*120/(831-660),3), ' mW'],
> 'Position', [600, 80], 'Color', 'white', 'FontSize', 15);
> f = getframe(gca);
> imwrite(f.cdata, [num2str(i), '.bmp']);
> end;
> -- snap --
>
> Now my problem: The original files have a size of 800 x 600 pixels.
>
> What I get with imwrite does not have 800x600 Pixels.
> How do I tell the axes object to have exactly an extend of 800 x 600
> pixels on my screen so that imwrite produces figures of 800x600 px?
>
> Thank you
> Pascal

I expected GETFRAME to work on the pixels in the axis, fooling around led
me here:
(something to start with for you)

imagesc(rand(600,800));
set(gca,'DataAspectRatio', [1,1,1],'PlotBoxAspectRatio',[1 1 1])
set(gca, 'Box', 'off', 'GridLineStyle', 'none', 'XGrid', 'off',...
     'XTick', [], 'YTick', []);
text('String', ['P_{mw}=', num2str((i-660)*120/(831-660),3), ' mW'],...
     'Position', [400, 80], 'Color', 'black', 'FontSize', 15);

set(gcf,'position',[50 50 810 610]); %something larger than the axis
set(gca,'Units','pixels'); %easier to specify
set(gca,'position',[8 8 800 599]); %


f = getframe(gca);size(f.cdata)

%imwrite(f.cdata,'o.bmp');

Tags for this Thread

No tags are associated with 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