954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help making grayscale (intensity map) images in PyGtk !!

Hello!
I am trying to display a FITS image, if your not familiar with the extension its fine (gtk.Image.new_from_file() isn't either). I can get my image data to a numpy array (2D (256x256 to be exact)) I am having the most difficult time getting this into a grayscale image. I've tried gtk.Image() Ive tried pixbufs and pixmaps everything on the web. I'm having trouble making the color scales/maps. Something about visuals? My computer didn't have any that would work (debian linux). I've been slamming my head against the wall for days over this one and It seems like it should be so simple. Thanks for your help/suggestions!!!


Here is the eventual implementation:

#!/usr/bin/python
#filename: imgTest.py


import gtk
import pyfits as pf
import numpy as np

class PyApp(gtk.Window):

   def __init__(self):
      super(PyApp, self).__init__()
      self.set_title("image test")
      self.set_position(gtk.WIN_POS_CENTER)
      self.connect("destroy", gtk.main_quit)
#--------------------------------------------------------------------------------
      data = abs(np.matrix(pf.getdata('img.fits')))
      data = data*(255.0/data.max())
      [w,h] = np.shape(data)
      #I need to take the array 'data' and display it as an image 
	

#--------------------------------------------------------------------------------
      self.show_all()

PyApp()
gtk.main()
tehbrozor
Newbie Poster
14 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

So pylab has colormaps, but they dont work as gtk.gdk.Colormap() is there any way to convert maybe?

#--------------------------------------------------------------------------------
      data = abs(np.matrix(pf.getdata('img.fits')))
      data = data*(255.0/data.max())
      [w,h] = np.shape(data)
      cmap = pylab.get_cmap('gray')
      window = gtk.Window()
      pm = gtk.gdk.Pixmap(None,256,256,8)
      pm.set_colormap(cmap)
      gc = pm.new_gc()
      pm.draw_gray_image(gc,0,0,256,256,gtk.gdk.RGB_DITHER_NONE,data)
#--------------------------------------------------------------------------------

The error message:kevin@rainier sandbox% python imgTest.py
The gdk_draw_*_image require the drawable argument to
have a specified colormap. All windows have a colormap,
however, pixmaps only have colormap by default if they
were created with a non-NULL window argument. Otherwise
a colormap must be set on them with gdk_drawable_set_colormap
kevin@rainier sandbox% python imgTest.py
Traceback (most recent call last):
File "imgTest.py", line 36, in
PyApp()
File "imgTest.py", line 25, in __init__
pm.set_colormap(cmap)
TypeError: GdkDrawable.set_colormap() argument 1 must be gtk.gdk.Colormap, not instance

tehbrozor
Newbie Poster
14 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: