imread (repost)

Bill Denney bill at denney.ws
Tue Aug 5 18:34:59 CDT 2008


Thomas L. Scofield wrote:
> On Aug 5, 2008, at 12:53 AM, Søren Hauberg wrote:
>> man, 04 08 2008 kl. 21:57 -0400, skrev Thomas L. Scofield
>>> At least some png image files (BMP and PSD files as well, I believe)
>>> use 4 channels: red, green, blue and alpha.  For those files, imread
>>> returns an array A satisfying size (A, 3) = 4..  (Would it do so as
>>> well for files using CMYK color space?)  As such, the matrix A in
>>> which the image is stored cannot be sent off to imshow without
>>> limiting its 3rd coordinate, as in imshow (A(:, :, 1:3)).  The changes
>>> John Eaton made to imread.m as I submitted it were quite necessary,
>>> but in the process code I had included for limiting this 3rd
>>> coordinate in imread before ever returning the image was lost.  Should
>>> it be reinstated?  Or, should imshow be modified to handle the
>>> occasional image like these png files?  I don't mind making the
>>> changes, but lean towards altering imshow instead of imread if this
>>> doesn't result in an unacceptable incompatability with Matlab.
>>> Interestingly, when I read this same kind of png into Matlab, it
>>> returns a 2D matrix, not 3 like in Octave and, subsequently, it
>>> displays the image as grayscale when it was really a color image (the
>>> Octave call imshow(A(:, :, 1:3)) gets the color right).  (Perhaps that
>>> is remedied in Matlab with optional arguments to imread.)
>>
>> The matlab version of imread supports an extra output argument that
>> contains the alpha channel of an image. I don't think it is trivial (nor
>> a good idea) to change imshow to make it possible to show images with an
>> alpha channel. I mean, what should be to visual result when showing an
>> image that s 100% transparent? I'd stick with showing RGB only.
>
> That's not the kind of modification I was suggesting for imshow.  I 
> was suggesting this much simpler change (pseudocode):
>
>   if (length (size (image)) == 3 && size (image, 3) == 4)
>     show image(:, :, 1:3)
>   else
>     show image
>   endif

I would think that the above would be fine as long as it gave a warning 
before the "show image(:,:,1:3)".

Have a good day,

Bill


More information about the Octave-maintainers mailing list