comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » problem with writing a 2D image .tiff
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
problem with writing a 2D image .tiff [message #53502] Wed, 18 April 2007 05:54 Go to next message
aleks.franca@gmail.co is currently offline  aleks.franca@gmail.co
Messages: 33
Registered: March 2007
Member
Hy
My code reads a 2D tiff image and I create a colortable with 6 levels.
It works fine, and I can visualize the result image, but I'm having a
hard time trying to write the image to my computer.

;Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
image = read_tiff('myImagePath\myImage.tiff'))

device, decompose = 0

colorLevels = [ [0 , 0 , 0 ], $
[0 , 0 , 255], $
[51 , 194, 255], $
[182, 255, 143], $
[255, 200, 0 ], $
[255, 0 , 0 ] ]

numOfLevel = CEIL(!D.TABLE_SIZE/6.)
level = INDGEN(!D.TABLE_SIZE)/numOfLevel

newRed = colorLevels[0, Nivel]
newGreen = colorLevels[1, Nivel]
newBlue = colorLevels[2, Nivel]

TVLCT, newRed, newGreen, newBlue

x = 900
y = 600

;;Visualize result image
image = CONGRID(image, x, y)

WINDOW, 0, xSize = x, ySize = y

TVSCL, image, /order

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


This first part works fine. The problem is below, when I try to write
the result image

;;;;;;;;
;;;;;;;;using write_tif
;;;;;;;;
;;_______TIF
newRed = reform(newRed)
newGreen = reform(newGreen)
newBlue = reform(newBlue)

Write_tiff, 'C:\IDL\tests\mytif.tif', image, $
RED=newred,GREEN=newgreen,BLUE=newblue
;;;;;;;;
;;;;;;;;I've also tried using write_Jpeg
;;;;;;;;
;_______JPEG
array = bytarr(3,x,y)
array[0,*,*] = newred[image]
array[1,*,*] = newgreen[image]
array[2,*,*] = newblue[image]

Write_jpeg, 'C:\IDL\tests\myimage.jpg',array, TRUE = 1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;

Does anyone have any idea whats wrong? I'm sure its very easy problem
to treat, but I'm stuck on this problem for 1 week.

Thank you
Aleksander
Re: problem with writing a 2D image .tiff [message #53571 is a reply to message #53502] Wed, 18 April 2007 19:08 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
aleks.franca@gmail.com writes:

> I forgot to say that I can't visualize my image after I write it to
> disk using write_tiff or write_jpeg.
> Sorry.

Well, why not? You tried....what? It it looked like...what?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: problem with writing a 2D image .tiff [message #53614 is a reply to message #53502] Fri, 20 April 2007 08:26 Go to previous messageGo to next message
Jeff N. is currently offline  Jeff N.
Messages: 120
Registered: April 2005
Senior Member
I used your code, changing the input file to the 'image.tif' file in
the examples\data folder, and got decent tif and jpg files. I also
changed the variable "Nivel" to "level" in your code. The tif and jpg
files weren't exactly like what was displayed on screen - the color
levels were different, but they at least were not black like what you
were getting.

Jeff
Re: problem with writing a 2D image .tiff [message #53615 is a reply to message #53502] Fri, 20 April 2007 08:09 Go to previous messageGo to next message
Jeff N. is currently offline  Jeff N.
Messages: 120
Registered: April 2005
Senior Member
Try opening one of the tif or jpg files you created with your code in
envi. Using the cursor location/value tool you can see the pixel
values stored in the image. Are they what you expect? If they're all
zero's, that's why your image is black. In your original code, what
are you storing in the variable Nivel?
Re: problem with writing a 2D image .tiff [message #53634 is a reply to message #53502] Thu, 19 April 2007 14:17 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
aleks.franca@gmail.com writes:

> I have a geotif image. After a use Write_jpeg, ow Write_tiff, as
> showed above, the image appears all black. That happens when I open it
> with a Windows software. With Envi I can visualize my image, but
> that's not interesting for me.

Well, I don't know. It is hard to debug a secret process.

Have you tried writing your image with TVREAD? I've never known
that NOT to work.

http://www.dfanning.con/programs/tvread.pro

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: problem with writing a 2D image .tiff [message #53636 is a reply to message #53571] Thu, 19 April 2007 12:52 Go to previous messageGo to next message
aleks.franca@gmail.co is currently offline  aleks.franca@gmail.co
Messages: 33
Registered: March 2007
Member
On 18 abr, 23:08, David Fanning <n...@dfanning.com> wrote:
> aleks.fra...@gmail.com writes:
>> I forgot to say that I can't visualize my image after I write it to
>> disk using write_tiff or write_jpeg.
>> Sorry.
>
> Well, why not? You tried....what? It it looked like...what?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

I have a geotif image. After a use Write_jpeg, ow Write_tiff, as
showed above, the image appears all black. That happens when I open it
with a Windows software. With Envi I can visualize my image, but
that's not interesting for me.
Re: problem with writing a 2D image .tiff [message #53796 is a reply to message #53502] Thu, 03 May 2007 10:09 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
aleks.franca@gmail.com writes:

> ok. I have the solution to my problem. I work with grayscale images
> and they have only 6 diferent pixel values. From 0 to 6. I can
> visualize the image because I created a 6-level-colortable to
> visualize, but when I save it, I cannot see the image because the
> pixel values are very low.
> To save it the way I can actually see the image I have to use the
> command:
>
> image = bytscl(image)
>
> Now I'm confused. Why did that work?

Because now your values are not 0-5, they are this:

IDL> Print, Bytscl(Indgen(6))
0 51 102 153 204 255

And these values show up in the color table you are
using. But this is NOT what you want to do.

What you WANT to do, is load the six colors you are
using to display your image, and scale your image
into those six colors. Something like this:

LoadCT, 33, NCOLORS=6, BOTTOM=1
TV, BytScl(image, TOP=5) + 1B

In general, if you care about colors (and who doesn't!?),
then you should forget you ever heard about TVSCL. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: problem with writing a 2D image .tiff [message #53797 is a reply to message #53614] Thu, 03 May 2007 09:58 Go to previous message
aleks.franca@gmail.co is currently offline  aleks.franca@gmail.co
Messages: 33
Registered: March 2007
Member
On 20 abr, 12:26, "Jeff N." <jnett...@utk.edu> wrote:
> I used your code, changing the input file to the 'image.tif' file in
> the examples\data folder, and got decent tif and jpg files. I also
> changed the variable "Nivel" to "level" in your code. The tif and jpg
> files weren't exactly like what was displayed on screen - the color
> levels were different, but they at least were not black like what you
> were getting.
>
> Jeff

ok. I have the solution to my problem. I work with grayscale images
and they have only 6 diferent pixel values. From 0 to 6. I can
visualize the image because I created a 6-level-colortable to
visualize, but when I save it, I cannot see the image because the
pixel values are very low.
To save it the way I can actually see the image I have to use the
command:

image = bytscl(image)

Now I'm confused. Why did that work?

Thank you!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: HISTOGRAM and string data
Next Topic: how to force idl to export data in one line?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 07:51:16 PDT 2025

Total time taken to generate the page: 0.08653 seconds