# IMWrite fuction is not what it seems...

**URL:** <https://psychtoolbox.discourse.group/t/imwrite-fuction-is-not-what-it-seems/930>\
**Category:** Uncategorized\
**Created:** [February 3, 2003, 1:54pm UTC](https://psychtoolbox.discourse.group/t/imwrite-fuction-is-not-what-it-seems/930 "2003-02-03T13:54:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranibaron](https://avatars.discourse-cdn.com/v4/letter/r/b3f665/32.png) [@ranibaron](https://psychtoolbox.discourse.group/u/ranibaron)\
**Post date:** [February 3, 2003, 1:54pm UTC](https://psychtoolbox.discourse.group/t/imwrite-fuction-is-not-what-it-seems/930/1 "2003-02-03T13:54:38Z")

</div>

Hi all,  
  
I have problems translating a vector into an image.  
The image is a 256 grayscale - a simple Gabor patch  
from the GratingDemo.m file. When I try to transform  
it to image by adding:  
  
IMWRITE(m,'Gabor.jpg','jpg');  
  
- m is the gabor from the demo.  
  
I see the correct Gabor patch on the screen but when  
opening the .jpg file created I get attached image.  
  
I work with 1024\*768 \* 120Hz \* Millions of colors  
MacOS9.2.2 on a new G4 machine.  
Matlab 5.2.1  
Latest psychtoolbox  
  
Thanks in advance,  
  
Rani Bar-On  
IIPDM  
Psychology Department  
University of Haifa  
  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Do you Yahoo!?  
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.  
[http://mailplus.yahoo.com](http://mailplus.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [February 4, 2003, 8:53am UTC](https://psychtoolbox.discourse.group/t/imwrite-fuction-is-not-what-it-seems/930/2 "2003-02-04T08:53:24Z")

</div>

dear rani  
your image is inappropriately scaled and cast. 'm' is an array  
of doubles in the range -1 to +1. to write with 'imwrite' make it  
a 'uint' (unsigned integer) in the range 0 to 255, thus:  
imwrite(uint8(128+127.\*m),'Gabor.jpg','jpg');  
good luck  
steven dakin  
-----  
Steven Dakin  
Institute of Ophthalmology  
11-43 Bath Street  
London EC1V 9EL  
  
Lab: +44 20 7608 6988  
Office: +44 20 7608 6928  
Fax: +44 20 7608 6850  
Web: [http://www.homepages.ucl.ac.uk/~smgxscd](http://www.homepages.ucl.ac.uk/~smgxscd)
