problem with writing a 2D image .tiff [message #53502] |
Wed, 18 April 2007 05:54  |
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 #53636 is a reply to message #53571] |
Thu, 19 April 2007 12:52   |
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  |
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  |
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!
|
|
|