White images with 'imshow'

John W. Eaton jwe at octave.org
Wed May 27 05:41:46 CDT 2009


On 27-May-2009, Jaroslav Hajek wrote:

| On Wed, May 27, 2009 at 12:20 AM, John W. Eaton <jwe at octave.org> wrote:
| > On 26-May-2009, Søren Hauberg wrote:
| >
| > | I honestly don't know the details of how Matlab works here. I would just
| > | do a
| > |
| > |   im = ind2rgb (X, map);
| > |
| > | if 'imshow' is called with an indexed image and a colormap. Sadly, I
| > | doubt that this is compatible, as I think Matlab stores the indexed
| > | image in the 'CData' of the handle returned by 'imshow'.
| > |
| > | Does anybody have an idea of when (or if) Matlab converts between
| > | indexed and RGB images when they are showed?
| >
| > OK, I don't know what the right change is then.  But my change is not
| > the right thing, so I undid it.
| 
| You forgot to push, apparently. I backed out the changeset myself to proceed.
| 
| > This is another bug that should be fixed before 3.2.0 is released
| > because imshow is doing the wrong thing for indexed images.  I thought
| > it used to work at some point, but it also seems broken in 3.0.5.
| >
| 
| I checked in the following changeset which seems to solve the problem:
| http://hg.savannah.gnu.org/hgweb/octave/rev/06518194dba0

Thanks.

This demo:

  imshow example 4:
    [I, M] = loadimage ("default.img");
    imshow (cat(3, I, I*0.5, I*0.8));

still seems to produce a white image, but I think that is now expected
since I is double, so should be scaled between 0 and 1?  This
operation doesn't really make sense with an indexed image anyway, does
it?  I guess the demo should really be

  [r, g, b] = ind2rgb (I, M);
  imshow (uint8 (cat (3, r, g*0.5, b*0.8)));

so I made this change and also changed the demos to use imread instead
of loadimage.

Now I see that

  [I, M] = imread ("default.img");
  [r, g, b] = ind2rgb (I, M);
  imwrite (cat (3, r, g, b), "foo.png")

works, but

  imwrite (I, M, "foo.png")

fails with

  error: Magick++ exception: Magick: Color argument is invalid reported by Exception.cpp:272 (throwExceptionExplicit)
  error: called from:
  error:   /home/jwe/src/octave/scripts/image/imwrite.m at line 148, column 7

This call to imwrite is equivalent to

  __magick_write__ ("foo.png", "png", uint8 (I - 1), M);

>From what I can tell, the encode_uint_image function in
src/DLD-FUNCTIONS/__magick_read__.cc is not doing the right thing for
this kind of indexed image.  I don't know much about GraphicsMagick.
Does anyone have a clue what should be happening?

jwe



More information about the Bug-octave mailing list