Got Questions? Get Answers.
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:
how to remove border figure window, bitmap image, and save file?

Subject: how to remove border figure window, bitmap image, and save file?

From: Bruno

Date: 18 Mar, 2010 16:50:04

Message: 1 of 3

Hello,

How to remove the Figure window frame around a imshow( )
image and save a bitmap file, with exactly resY x resX pixels.

Details follow.

Thanks,
Marchesi.

--------------------------------------------------------------------------------------------------



Consider this:

Ihandle = gcf;
Ahandle = axes('parent', Ihandle);

imshow(imadjust(AnImage)), hold on
himage = imshow(label2rgb(L, @jet, 'w'));
set(himage, 'AlphaData', 0.3);

After this, there are some plot commands. The resulting image should be saved in
a bitmap file (png, bmp). I know the image got to be 240x320, as the original 'AnImage' image.

The thing is, there's this frame, this border around the figure window. How could I get rid of this border, and save the image with resY x resX pixels? This must be done by code, not by GUI.
The figure and axes handles (Ihandle and Ahandle) are available to do that.

I'm using print/deployprint to save the bitmaps, something like this:

set(Ihandle, 'Position', [1 1 320 240]);
if isdeployed
deployprint(['-f',int2str(Ihandle)], '-r0', ...
    [dialog.outputPath dialog.outputFilename '.bmp']);
else
print(['-f',int2str(Ihandle)],'-dpng', '-r0', ...
    [dialog.outputPath dialog.outputFilename '.png']);
end

Thanks,
Marchesi

Subject: how to remove border figure window, bitmap image, and save file?

From: Bruno

Date: 19 Mar, 2010 12:46:04

Message: 2 of 3

bump

An option would be to assign a background color to the border, and then
extract it off the saved bitmap file, as a post-processing. It's somewhat
dumb, but it's the best shot so far.

Subject: how to remove border figure window, bitmap image, and save file?

From: Bruno

Date: 23 Mar, 2010 17:53:23

Message: 3 of 3

I did this:

i1 = imread(imageFileName);

[x, y, rgb] = ind2sub([size(i1,1) size(i1,2) size(i1,3)], find(i1 ~= 255));
i1 = i1(min(x):max(x)-1,min(y):max(y)-1,:);

imwrite(i1,imageFileName);


It reopens the bitmap and looks for the occurences of a ~(border color),
keeping them and saving the result as a new one. It worked for me 5 by 5.
The disadvantage is that there should be one color not to be used on the
bitmap. The search could be refined though, to overcome this feature.

Marchesi.

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