imread.m fails reading/writing 16bit images correctly

Tatsuro MATSUOKA tmacchant at yahoo.co.jp
Wed Jul 1 19:39:52 CDT 2009


Hello 

Sorry for my separated post.

I have attached your changeset and testet

octave:5> imwrite(uint16([12345,12346,12347]), "test2.tiff");
octave:6>  img=imread("test2.tiff")
img =

  12344  12345  12346

The results are the same as yours.

Regards

Tatsuro

--- Tatsuro MATSUOKA <tmacchant at yahoo.co.jp> wrote:

> Hello
> 
> I have tested in my cygwin build using octave-3.2.1-rc1 on cygwin-1.5.25-15.
> Graphicsmagick is configured with 
> CC=gcc-4 CXX=g++-4 F77=gfortran-4 CFLAGS='-O3 -fomit-frame-pointer' CXXFLAGS='-O3
> -fomit-frame-pointer' FFLAGS='-O3 -fomit-frame-pointer'  ./configure --enable-shared 
> --enable-static
> --disable-openmp --with-quantum-depth=16 --without-threads
> --with-windows-font-dir=C:/WINDOWS/Fonts
> 
> 
> octave:4>  imwrite(uint16(12345),"test.tiff");
> octave:5> img=imread("test.tiff")
> img = 48
> octave:6> class(img)
> ans = uint8
> octave:7> imfinfo("test.tiff")
> ans =
> {
>   Filename = /cygdrive/d/usr/Tatsu/program/Octave/test2/test.tiff
>   FileSize =  261
>   Height =  1
>   Width =  1
>   BitDepth =  16
>   Format = TIFF
>   LongFormat = Tagged Image File Format
>   XResolution = 0
>   YResolution = 0
>   TotalColors =  1
>   TileName = 
>   AnimationDelay = 0
>   AnimationIterations = 0
>   ByteOrder = undefined
>   Gamma = 0
>   Matte = 0
>   ModulusDepth =  13
>   Quality =  75
>   QuantizeColors =  256
>   ResolutionUnits = undefined
>   ColorType = grayscale
>   View = 
>   FileModDate =  2-Jul-2009 08:33:32
> }
> 
> The behaviors are the same as your reports.
> I will check your changeset from now.
> 
> 
> Regards
> 
> Tatsuro
> 
> --- Benjamin Lindner  wrote:
> 
> > Hello,
> > 
> > using current development sources on mingw32, together with 
> > graphicsmagick-1.3.5 configured with --quantum-depth=16, imread does not
> > correctly read 16bit images.
> > 
> > octave.exe:2:C:\> imwrite(uint16(12345),"test.tiff");
> > octave.exe:3:C:\> img=imread("test.tiff")
> > img = 48
> > octave.exe:4:C:\> class(img)
> > ans = uint8
> > octave.exe:5:C:\> imfinfo("test.tiff")
> > ans =
> > {
> >   Filename = C:\test.tiff
> >   FileSize =  261
> >   Height =  1
> >   Width =  1
> >   BitDepth =  16
> >   Format = TIFF
> >   LongFormat = Tagged Image File Format
> >   XResolution = 0
> >   YResolution = 0
> >   TotalColors =  1
> >   TileName =
> >   AnimationDelay = 0
> >   AnimationIterations = 0
> >   ByteOrder = undefined
> >   Gamma = 0
> >   Matte = 0
> >   ModulusDepth =  13
> >   Quality =  75
> >   QuantizeColors =  256
> >   ResolutionUnits = undefined
> >   ColorType = grayscale
> >   View =
> >   FileModDate = 29-Jun-2009 11:40:51
> > }
> > 
> > The reason (I believe) is that __magick_read__.cc (staring at line 418) 
> > determines from ModulusDepth the number of bits required to store image data 
> > into incorrectly.
> > With the above Modulusdepth=13, the calculated bitdepth is 8, when it should 
> > be 16.
> > 
> > The attached changeset fixes this, but it still does not work correctly.
> > 
> > octave.exe:5:C:\> imwrite(uint16([12345,12346,12347]), "test2.tiff");
> > octave.exe:6:C:\> img=imread("test2.tiff")
> > img =
> > 
> >   12344  12345  12346
> > 
> > the values read are off-by-1.
> > 
> > And apparently they are already written off-by-1
> > 
> > c:\> tiffinfo -d test2.tiff
> > TIFF Directory at offset 0xe (14)
> >   Image Width: 3 Image Length: 1
> >   Bits/Sample: 16
> >   Sample Format: unsigned integer
> >   Compression Scheme: None
> >   Photometric Interpretation: min-is-black
> >   Samples/Pixel: 1
> >   Rows/Strip: 1365
> >   Planar Configuration: single image plane
> >   Page Number: 0-1
> >   DocumentName: test2.tiff
> >   Software: GraphicsMagick 1.3.5 2009-01-26 Q16 http://www.GraphicsMagick.org/
> > Strip 0:
> >  38 30 39 30 3a 30
> > 
> > and 0x3038 equals 12344 decimal, so something's wrong at creating the image file
> > I couldn't yet figure out why this is so.
> > Can someone confirm this behavoiur? 
> > 
> > benjamin
> > -- 
> > GRATIS f将舐 alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> > > # HG changeset patch
> > # User Benjamin Lindner <lindnerb at users.sourceforge.net>
> > # Date 1246274961 -7200
> > # Node ID c39f66e65f188f1f405f6ed74bb8c3b757e2a203
> > # Parent  34c8e1d9c9c273e10ad7f6cc9fdd8ddd5db6ed77
> > determine correct image bitwidth in __magick_read__.cc
> > 
> > diff -r 34c8e1d9c9c2 -r c39f66e65f18 src/ChangeLog
> > --- a/src/ChangeLog	Thu Jun 25 09:44:06 2009 +0200
> > +++ b/src/ChangeLog	Mon Jun 29 13:29:21 2009 +0200
> > @@ -1,3 +1,8 @@
> > +2009-06-29  Benjamin Lindner <lindnerb at users.sourceforge.net>
> > +
> > +	* DLD-FUNCTIONS/__magick_read__.cc (F__magick_read__): Determine correct number 
> > +	of bits required when reading images.
> > +
> >  2009-06-14  Jaroslav Hajek  <highegg at gmail.com>
> >  
> >  	* DLD-FUNCTIONS/lookup.cc (Flookup): Support character array lookup.
> > diff -r 34c8e1d9c9c2 -r c39f66e65f18 src/DLD-FUNCTIONS/__magick_read__.cc
> > --- a/src/DLD-FUNCTIONS/__magick_read__.cc	Thu Jun 25 09:44:06 2009 +0200
> > +++ b/src/DLD-FUNCTIONS/__magick_read__.cc	Mon Jun 29 13:29:21 2009 +0200
> > @@ -416,11 +416,15 @@
> >    else
> >      {
> >        unsigned int depth = imvec[0].modulusDepth ();
> > -      int i = 0;
> > -      while (depth >>= 1)
> > -        i++;
> > -      depth = 1 << i;
> > -
> > +      if (depth > 1)
> > +	{
> > +	  --depth;
> > +	  int i = 1;
> > +	  while (depth >>= 1)
> > +	  i++;
> > +	  depth = 1 << i;
> > +	}
> > +      
> >        switch (depth)
> >          {
> >          case 1:
> > > _______________________________________________
> > Bug-octave mailing list
> > Bug-octave at octave.org
> > https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave
> > 
> 
> 
> --------------------------------------
> Power up the Internet with Yahoo! Toolbar.
> http://pr.mail.yahoo.co.jp/toolbar/
> _______________________________________________
> Bug-octave mailing list
> Bug-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave
> 


--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/


More information about the Bug-octave mailing list