Thread Subject: Printing an image to scale

Subject: Printing an image to scale

From: Joshua Fialkoff

Date: 3 Apr, 2008 04:52:01

Message: 1 of 9

Hi all,
Say we import an image into MATLAB. I can print/export that
image at the same resolution and using the same file type
and have the same image (i.e., it will match the dimensions
of the original). Similarly, I can perform some operations
directly on the matrix that represents the image and, again,
export and get a similarly sized image. The problem is
this. I would like to show the image using imshow and then
overlay some shapes (e.g., bounding boxes, etc...) and then
export the image such that it is similarly sized as the
original. I can't seem to figure out how to accomplish
this. If it helps I'm only working with B&W images, but a
more generic solution is preferable. Thanks in advance for
you help.

- Josh

Subject: Printing an image to scale

From: Bryan

Date: 3 Apr, 2008 06:03:06

Message: 2 of 9

"Joshua Fialkoff" <fialkj@rpi.edu> wrote in message
<ft1nph$5rv$1@fred.mathworks.com>...
> Hi all,
> Say we import an image into MATLAB. I can print/export that
> image at the same resolution and using the same file type
> and have the same image (i.e., it will match the dimensions
> of the original). Similarly, I can perform some operations
> directly on the matrix that represents the image and, again,
> export and get a similarly sized image. The problem is
> this. I would like to show the image using imshow and then
> overlay some shapes (e.g., bounding boxes, etc...) and then
> export the image such that it is similarly sized as the
> original. I can't seem to figure out how to accomplish
> this. If it helps I'm only working with B&W images, but a
> more generic solution is preferable. Thanks in advance for
> you help.
>
> - Josh

you want some version of:

imgMod = get(findobj('type','image),'Cdata');

with more than one figure open, you can use 'gcf' or 'get'
with the figure number, whatever.

there's some other way to do it, i think, but that comes to
mind.

bryan

Subject: Printing an image to scale

From: Joshua Fialkoff

Date: 3 Apr, 2008 14:39:02

Message: 3 of 9

Thanks for the help. I don't think this is accomplishing
what I'm looking for. I performed the following:

img = imread('somefile.tif');
imshow(img);
rectangle('position', [0 0 100 100]);
img2 = get(findobj('type','image'), 'cdata');
imshow(img2);

The result is the original image. What I desire is a
composite image (i.e., an image that is somefile.tif with a
square overlaid).

- Josh

Subject: Printing an image to scale

From: Bryan

Date: 3 Apr, 2008 16:34:03

Message: 4 of 9

"Joshua Fialkoff" <fialkj@rpi.edu> wrote in message
<ft2q66$aj8$1@fred.mathworks.com>...
> Thanks for the help. I don't think this is accomplishing
> what I'm looking for. I performed the following:
>
> img = imread('somefile.tif');
> imshow(img);
> rectangle('position', [0 0 100 100]);
> img2 = get(findobj('type','image'), 'cdata');
> imshow(img2);
>
> The result is the original image. What I desire is a
> composite image (i.e., an image that is somefile.tif with a
> square overlaid).
>

oops... yes, i understood what you meant, and thought this
would do it (was not at a matlab computer, so couldn't test
it). i'll get back to you if i figure it out.


Subject: Printing an image to scale

From: Steven Lord

Date: 3 Apr, 2008 16:36:33

Message: 5 of 9


"Joshua Fialkoff" <fialkj@rpi.edu> wrote in message
news:ft2q66$aj8$1@fred.mathworks.com...
> Thanks for the help. I don't think this is accomplishing
> what I'm looking for. I performed the following:
>
> img = imread('somefile.tif');
> imshow(img);
> rectangle('position', [0 0 100 100]);
> img2 = get(findobj('type','image'), 'cdata');
> imshow(img2);
>
> The result is the original image. What I desire is a
> composite image (i.e., an image that is somefile.tif with a
> square overlaid).

You might want to look at the GETFRAME or PRINT functions. [PRINT to an
image file, then read in the image to get the modified data back into
MATLAB.]

--
Steve Lord
slord@mathworks.com


Subject: Printing an image to scale

From: Bryan

Date: 3 Apr, 2008 16:57:12

Message: 6 of 9

"Steven Lord" <slord@mathworks.com> wrote in message
<ft312h$49e$1@fred.mathworks.com>...
>
> "Joshua Fialkoff" <fialkj@rpi.edu> wrote in message
> news:ft2q66$aj8$1@fred.mathworks.com...
> > Thanks for the help. I don't think this is accomplishing
> > what I'm looking for. I performed the following:
> >
> > img = imread('somefile.tif');
> > imshow(img);
> > rectangle('position', [0 0 100 100]);
> > img2 = get(findobj('type','image'), 'cdata');
> > imshow(img2);
> >
> > The result is the original image. What I desire is a
> > composite image (i.e., an image that is somefile.tif with a
> > square overlaid).
>
> You might want to look at the GETFRAME or PRINT functions.
 [PRINT to an
> image file, then read in the image to get the modified
data back into
> MATLAB.]
>
> --
> Steve Lord
> slord@mathworks.com
>

but if the image is displayed at anything other than 100%
this loses the original image dimensions... i think the op
wanted the _same_ image (dimensions), with the modifications
as part of the new image.

after looking around myself, i have also had trouble finding
this functionality. i tried to set the rectangle's parent
property to be the image, but that didn't work out.

in the trivial example given, the op could obviously just
change the color of the pixels in his original image that
define his rectangle, but this would get harder and harder
for non-simple annotations (and text!).

bryan

Subject: Printing an image to scale

From: Dan Haeg

Date: 4 Apr, 2008 00:09:02

Message: 7 of 9

"Joshua Fialkoff" <fialkj@rpi.edu> wrote in message
<ft1nph$5rv$1@fred.mathworks.com>...
> Hi all,
> Say we import an image into MATLAB. I can print/export that
> image at the same resolution and using the same file type
> and have the same image (i.e., it will match the dimensions
> of the original). Similarly, I can perform some operations
> directly on the matrix that represents the image and, again,
> export and get a similarly sized image. The problem is
> this. I would like to show the image using imshow and then
> overlay some shapes (e.g., bounding boxes, etc...) and then
> export the image such that it is similarly sized as the
> original. I can't seem to figure out how to accomplish
> this. If it helps I'm only working with B&W images, but a
> more generic solution is preferable. Thanks in advance for
> you help.
>
> - Josh

I have the same problem. My image is 5939 by 4639 pixels so
it is way too big for my screen when not zoomed. I read the
image and display it. Then I plot some non-trivial lines on
top of the image. Now I want to print the combined image
with lines to the same size file as the original ie 5939 by
4639. The image is true color.

Here is my thread:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423529

If anyone can solve both our problems that would be great,
thanks.
Dan

Subject: Printing an image to scale

From: M K

Date: 4 Apr, 2008 09:31:02

Message: 8 of 9

"Dan Haeg" <haegd@msoe.edu> wrote in message
<ft3riu$98e$1@fred.mathworks.com>...
> "Joshua Fialkoff" <fialkj@rpi.edu> wrote in message
> <ft1nph$5rv$1@fred.mathworks.com>...
> > Hi all,
> > Say we import an image into MATLAB. I can print/export that
> > image at the same resolution and using the same file type
> > and have the same image (i.e., it will match the dimensions
> > of the original). Similarly, I can perform some operations
> > directly on the matrix that represents the image and, again,
> > export and get a similarly sized image. The problem is
> > this. I would like to show the image using imshow and then
> > overlay some shapes (e.g., bounding boxes, etc...) and then
> > export the image such that it is similarly sized as the
> > original. I can't seem to figure out how to accomplish
> > this. If it helps I'm only working with B&W images, but a
> > more generic solution is preferable. Thanks in advance for
> > you help.
> >
> > - Josh
>
> I have the same problem. My image is 5939 by 4639 pixels so
> it is way too big for my screen when not zoomed. I read the
> image and display it. Then I plot some non-trivial lines on
> top of the image. Now I want to print the combined image
> with lines to the same size file as the original ie 5939 by
> 4639. The image is true color.
>
> Here is my thread:
>
http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423529
>
> If anyone can solve both our problems that would be great,
> thanks.
> Dan

Hi,

One method is described here:
http://www.mathworks.com/support/solutions/data/1-16WME.html?solution=1-16WME

However, the "background" image may not have exactly same
colors as the original when exported trough print().

load clown
figH = figure;
axH = axes('units','normalized','position',[0 0 1 1]);
imH = imshow(X,map,'parent',axH);
colormap(map);
hold on, patch([ 50 100 50]',[50 100 100]','r','LineWidth',3)
text(150,20,'Clown','color',[0 0
0],'fontweight','bold','fontsize',14)
axis off
    
figSize = size(X);
defRes = 100;
paperPos = fliplr(figSize/defRes);
set(figH,'PaperUnits','inches','PaperPosition',[0 0 paperPos]);
% "save" figure with annotations
print('-dpng','new.png',['-r',num2str(defRes)])


HTH,

M

Subject: Printing an image to scale

From: Joshua Fialkoff

Date: 7 Apr, 2008 15:15:03

Message: 9 of 9

Works like a charm...thanks much.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
image Joshua Fialkoff 3 Apr, 2008 00:55:06
exporting Joshua Fialkoff 3 Apr, 2008 00:55:06
printing Joshua Fialkoff 3 Apr, 2008 00:55:06
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com