Discussion:
How to load an image in guiqwt
Carlos Noriega
2011-06-07 00:53:03 UTC
Permalink
Hi everybody

guidata and guiqwt are great tools that I believe will simplify my
life a lot, thanks Pierre.
However, I am still trying to grasp the basic concepts of them.
In my application, I basically want to load an image, transform it,
digitize some coordinates and draw some objects (circle, lines, etc)
on the image.
It seems I could easily do that once I learn guidata and guiqwt!

My first problem is that when I load an image with guiqwt
(builder.make.image(), following your examples), even if I do not
declare a colormap (or declare it as None), the image colors are
changed.
So, how do I load an image with its native colors?
Should I load the image using PyQt.QImage or convert it to a numpy
array using your function and then plot the image?

Thanks the great Spyder, guidata and guiqwt!

Carlos
Carlos Pascual
2011-06-07 07:51:16 UTC
Permalink
Hi Carlos,
I guess that depends on the format of your image in.

For example, in my lab we work with CCD cameras that return images as NxM
arrays where the value at each element of the matrix represents the intensity
(a grayscale image). In this case, you can use the "gray" colormap, which will
put black for the bottom of the scale and white for the top.

We also have cameras that return RGB images (i.e., arrays of NxMx3). In this
case we show them using guiqwt.image.RGBImageItem , which can be constructed
using make.image or more explicitely with make.rgbimage. See the image_rgb.py
example from guiqwt-tests

I hope this helps
Post by Carlos Noriega
Hi everybody
guidata and guiqwt are great tools that I believe will simplify my
life a lot, thanks Pierre.
However, I am still trying to grasp the basic concepts of them.
In my application, I basically want to load an image, transform it,
digitize some coordinates and draw some objects (circle, lines, etc)
on the image.
It seems I could easily do that once I learn guidata and guiqwt!
My first problem is that when I load an image with guiqwt
(builder.make.image(), following your examples), even if I do not
declare a colormap (or declare it as None), the image colors are
changed.
So, how do I load an image with its native colors?
Should I load the image using PyQt.QImage or convert it to a numpy
array using your function and then plot the image?
Thanks the great Spyder, guidata and guiqwt!
Carlos
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
E-mail: cpascual-***@public.gmane.org
Phone: +34 93 592 4428
+----------------------------------------------------+
Carlos Noriega
2011-06-09 18:58:47 UTC
Permalink
hi, Carlos
thanks very much
Post by Carlos Pascual
Hi Carlos,
I guess that depends on the format of your image in.
For example, in my lab we work with CCD cameras that return images as NxM
arrays where the value at each element of the matrix represents the intensity
(a grayscale image). In this case, you can use the "gray" colormap, which will
put black for the bottom of the scale and white for the top.
We also have cameras that return RGB images (i.e., arrays of NxMx3). In this
case we show them using guiqwt.image.RGBImageItem , which can be constructed
using make.image or more explicitely with make.rgbimage. See the image_rgb.py
example from guiqwt-tests
I hope this helps
Post by Carlos Noriega
Hi everybody
guidata and guiqwt are great tools that I believe will simplify my
life a lot, thanks Pierre.
However, I am still trying to grasp the basic concepts of them.
In my application, I basically want to load an image, transform it,
digitize some coordinates and draw some objects (circle, lines, etc)
on the image.
It seems I could easily do that once I learn guidata and guiqwt!
My first problem is that when I load an image with guiqwt
(builder.make.image(), following your examples), even if I do not
declare a colormap (or declare it as None), the image colors are
changed.
So, how do I load an image with its native colors?
Should I load the image using PyQt.QImage or convert it to a numpy
array using your function and then plot the image?
Thanks the great Spyder, guidata and guiqwt!
Carlos
--
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 Cells / Alba Synchrotron  [http:/www.cells.es]
 Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 Phone: +34 93 592 4428
+----------------------------------------------------+
Marcos Duarte
2011-06-07 14:29:49 UTC
Permalink
I am also a newbie and I have the same problem with images that do not have
the 3 RGB channels (image size NxMx3); I tried only guiqwt in windows.
For a rgb image, make.rgbimage works well but the image is upside down if
the file format is .png (try with the image attached). Make.image opens the
image in the correct orientation but messes with the colors.
For example, I have to do this to open the attached rgb image in .png
format:
...
image = imagefile_to_array(filename='brain.png')[::-1]

image = make.image(data=image)

...
Marcos Duarte
2011-06-07 22:10:35 UTC
Permalink
If you want to open an image with no RGB channels (2D image) in guiqwt,
open the image using PIL and use PIL convert to RGB method:
...
img_pil_2D = PIL.Image.open(filename)

img_pil_3D = img_pil_2D.convert(mode="RGB")

img_np = numpy.array(img_pil_3D)

image = make.image(data=img_np)

...


Marcos
Carlos Pascual
2011-06-09 16:40:48 UTC
Permalink
Regarding upside-down flipped images, the yreverse option may become handy. To
use it, when you construct the image dialog you pass it like:

win = ImageDialog(options=dict(yreverse=False))
Post by Marcos Duarte
I am also a newbie and I have the same problem with images that do not have
the 3 RGB channels (image size NxMx3); I tried only guiqwt in windows.
For a rgb image, make.rgbimage works well but the image is upside down if
the file format is .png (try with the image attached). Make.image opens the
image in the correct orientation but messes with the colors.
For example, I have to do this to open the attached rgb image in .png
...
image = imagefile_to_array(filename='brain.png')[::-1]
image = make.image(data=image)
...
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
E-mail: cpascual-***@public.gmane.org
Phone: +34 93 592 4428
+----------------------------------------------------+
Loading...