32bit tif to 8bit jp2 or tif -> peaks in histogram

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
tco95ttocs
Posts: 7
Joined: 2017-08-29T06:37:37-07:00
Authentication code: 1151

32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by tco95ttocs » 2017-08-29T22:24:41-07:00

Hi guys,

at first i want to say, that i'm new in using Magick.net, but i think something could be wrong when separating channels from a 4-channel 32bit tif to four 8bit greyscale jp2 or to four 8bit greyscale tif.
Visual the files are ok but when i have a look to the histogram, it seems to be broken! At several values there are big peaks, and next to them there is a hole!

I use VS2013 and tested with Q8, Q16, Q16-HDRI in Version 7.0.6.601 and 7.0.6.1002

Does anybody know how i can fix this?

Thx for helping:)

User avatar
fmw42
Posts: 22103
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by fmw42 » 2017-08-29T22:27:06-07:00

It would be most helpful is you provide the before and after images and their respective histograms and also your code. You can upload images to any free hosting service and put the URLs here.

Can you duplicate the issue using the command line? If so what command did you use?

I wonder if Imagemagick can handle 32-bits per channel for a 4 channel TIFF images or do you mean 32-bits total per image where the image has 4 8-bit channels. Post your input TIFF as suggested above so we can see what its characteristics are.

tco95ttocs
Posts: 7
Joined: 2017-08-29T06:37:37-07:00
Authentication code: 1151

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by tco95ttocs » 2017-08-30T02:46:06-07:00

Hi
at first here is my sample code:

Code: Select all

string img = Verzeichnis.Text + @"/" + selectedItem;
MagickImage bmp = new MagickImage(img);
foreach (var wert in bmp.Separate())
{
    i++;
    switch (i)
    {
        case 1:
           text = "R";
           break;
        case 2:
           text = "G";
           break;
        case 3:
           text = "B";
           break;
        case 4:
           text = "I";
        break;
   }
   wert.Write(Verzeichnis.Text + @"/"+text+"test.jp2");
}                         
So its not really complicated;)

The original tiff has four 8-bit channels.

The original you can find here
and two of the separated channels in greyscale you can find here (red) and
here (blue)

and the histograms are here:
https://picload.org/view/rwpdwcgw/histo ... g.png.html
https://picload.org/view/rwpdwcrr/histo ... d.png.html
https://picload.org/view/rwpdwcgi/histo ... e.png.html

i hope this helps :)

User avatar
fmw42
Posts: 22103
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by fmw42 » 2017-08-30T09:37:12-07:00

I do not see anything wrong or disturbing about your histogram. I get something similar in the command line of Imagemagick in IM 7.0.6.10 Q16 HDRI. The image has several different large regions of nearly similar gray shades. That is causing the peaks with valleys in-between.

I tried:

Code: Select all

convert luna.tif -separate luna_%d.tif

# red channel
convert luna_0.tif histogram:luna0tif.gif
Image

tco95ttocs
Posts: 7
Joined: 2017-08-29T06:37:37-07:00
Authentication code: 1151

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by tco95ttocs » 2017-08-30T23:05:14-07:00

i know that there are som higher peaks in the original file, but in the histograms i provided you can see the black and white lines!
and they comes when using the code above in VS 2013!

So where are they from?

I tested it with the command-line and i got the same wrong histogram when converting tif to jpg2000 (jp2), tif to tif its OK, looks like yours.

I see that you only separate from tif to tif and not from tif to jpg2000!
Can you check this again, please?

I played now with some versions of Magick.net.
And the histogram problem seems to be on all Versions newer than 7.0.0.14.
And with Versions between 7.0.0.2 and 7.0.0.14 the histogram is fine, but the final picture is a 24bit greyscale and not a 8 bit one.

So the latest version wich seems to produce the right image is 7.0.0.2!

User avatar
fmw42
Posts: 22103
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by fmw42 » 2017-08-31T10:41:55-07:00

Yes, I see the spikes with JP2. But there is a slight difference in the extracted red channel going to jp2 and going to png. So that might shift a few pixels one gray level differently. I do not know if this is a bug or a feature of JP2. But I will report it. See viewtopic.php?f=3&t=32606

tco95ttocs
Posts: 7
Joined: 2017-08-29T06:37:37-07:00
Authentication code: 1151

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by tco95ttocs » 2017-08-31T22:42:15-07:00

thx for helping :)
i hope the the repaired .net Version will follow as soon as possible!

User avatar
dlemstra
Posts: 1383
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by dlemstra » 2017-09-01T12:36:03-07:00

I will try to publish a new release of Magick.NET that includes this fix this weekend.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

tco95ttocs
Posts: 7
Joined: 2017-08-29T06:37:37-07:00
Authentication code: 1151

Re: 32bit tif to 8bit jp2 or tif -> peaks in histogram

Post by tco95ttocs » 2017-09-05T01:37:49-07:00

perfect new Magick.net Version 7.0.7 works fine :D

Post Reply