简体   繁体   English

使用 ImageJ 或 ImageJ 在线查看的 C# 库无法查看图像已尝试 ImageMagick 和 ImageSharp 和 System.Drawing

[英]Image not viewable using C# libraries viewable in ImageJ or ImageJ online have tried ImageMagick and ImageSharp and System.Drawing

I have a file that I can view in ImageJ but most software just shows it in black.我有一个可以在 ImageJ 中查看的文件,但大多数软件只是将其显示为黑色。 I am trying to view it in C# but it just comes up black, it is also not viewable in paint but I can view it in INcarta and ImageJ.我正在尝试在 C# 中查看它,但它只是变黑,在油漆中也看不到,但我可以在 INcarta 和 ImageJ 中查看它。 The file is a 16 bit tiff that seems to have LZW compression该文件是一个似乎有 LZW 压缩的 16 位 tiff

I am trying to use ImageSharp to decode this image and then show it as a bitmap.我正在尝试使用 ImageSharp 解码此图像,然后将其显示为 bitmap。 Here is a link to the file https://drive.google.com/file/d/16Xotc-2CJ6HkEJDysfKBkjClkU1OGiyQ/view?usp=sharing这是文件https://drive.google.com/file/d/16Xotc-2CJ6HkEJDysfKBkjClkU1OGiyQ/view?usp=sharing的链接

    byte[] data = File.ReadAllBytes(fileToDisplay1);
    
 

            SixLabors.ImageSharp.Formats.Tiff.TiffDecoder decoder = new SixLabors.ImageSharp.Formats.Tiff.TiffDecoder();
            SixLabors.ImageSharp.Formats.Tiff.TiffEncoder encoder = new SixLabors.ImageSharp.Formats.Tiff.TiffEncoder();
            SixLabors.ImageSharp.Image? image = SixLabors.ImageSharp.Image.Load(data, decoder);




            System.Drawing.Bitmap bMap;
            using (var ms = new MemoryStream())
            {
                image.Save(ms, encoder);
                bMap = new Bitmap(ms);
            }

I have also tried ImageMagickQ16我也试过 ImageMagickQ16

byte[] data = File.ReadAllBytes(fileToDisplay1);
                
                var decoder = new SixLabors.ImageSharp.Formats.Tiff.TiffDecoder();
                var encoder = new SixLabors.ImageSharp.Formats.Tiff.TiffEncoder();
                //encoder.BitsPerPixel = SixLabors.ImageSharp.Formats.Tiff.TiffBitsPerPixel.Bit16;
                var image = SixLabors.ImageSharp.Image.Load(data, decoder);
                MagickImage im2;



               using (var ms = new MemoryStream())
                {
                    image.Save(ms, encoder);
                    im2 = new MagickImage(ms.ToArray());
                }



               //im2.Depth = 16;
                //im2.Grayscale();
                im2.AutoLevel();



               return im2.ToBitmap();

The File Looks like this: in ImageJ but is black when I upload it or when I try to use other software.文件看起来像这样:在 ImageJ 中,但是当我上传它或尝试使用其他软件时是黑色的。 在此处输入图像描述

II have commented out other things I have tried我已经评论了我尝试过的其他事情

Imagemagick identify -verbose thinks your data is binary, just black and white. Imagemagick identify -verbose 认为您的数据是二进制的,只是黑白的。 So there is some error in Imagemagick.所以Imagemagick有一些错误。

Image:
  Filename: mystery.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 2040x2040+0+0
  Units: PixelsPerInch
  Colorspace: Gray
  Type: Bilevel
  Base type: Grayscale
  Endianness: LSB
  Depth: 16/1-bit
  Channel depth:
    gray: 1-bit
  Channel statistics:
    Pixels: 4161600
    Gray:
      min: 0  (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: -3
      skewness: 0
      entropy: 0
  Colors: 1
  Histogram:
       4161600: (0,0,0) #000000000000 gray(0)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 2040x2040+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: LZW
  Orientation: TopLeft
  Properties:
    date:create: 2022-09-27T00:43:06+00:00
    date:modify: 2022-09-27T00:42:39+00:00
    date:timestamp: 2022-09-27T00:43:25+00:00
    signature: 28f00fa3c1987b7b8f92961ef3a2d442cca23dbbb7c568b8908cc2fa2271de60
    tiff:alpha: unspecified
    tiff:endian: lsb
    tiff:photometric: min-is-black
  Artifacts:
    filename: mystery.tif
    verbose: true
  Tainted: False
  Filesize: 48240B
  Number pixels: 4161600
  Pixels per second: 84.8629MB
  User time: 0.060u
  Elapsed time: 0:01.049
  Version: ImageMagick 6.9.12-64 Q16 aarch64 17467 https://legacy.imagemagick.org

Mac Preview, GraphicConverter and Photoshop can read your image, but the gray levels are very low for a 16-bit range. Mac Preview、GraphicConverter 和 Photoshop 可以读取您的图像,但 16 位范围内的灰度级非常低。 Thus they appear at first glance as black.因此,它们乍一看是黑色的。 If the image dynamic range is stretched, the features show up.如果图像动态范围被拉伸,就会出现特征。

But this does not work with Imagemagick since it thinks the data is binary and as such all the data values being very low have been put into the black bin.但这不适用于 Imagemagick,因为它认为数据是二进制的,因此所有非常低的数据值都已放入黑色 bin。

Post and error to the Imagemagick web site at https://github.com/ImageMagick/ImageMagick/issues将错误发布到https://github.com/ImageMagick/ImageMagick/issues的 Imagemagick web 站点

This is either a bug in Imagemagick or your file is malformed according to the tiff documentation.这可能是 Imagemagick 中的错误,或者您的文件根据 tiff 文档格式不正确。 The IM developers will need to decide which. IM 开发人员需要决定使用哪个。

By default, the TiffDecoder will decode images as Rgba32 when using the non-generic API, ( something we can look into updating for v3 based upon the bit depth ), so you will not be capturing the image information since you are squashing 16bpp info into 8bpp.默认情况下,当使用非通用 API 时,TiffDecoder 会将图像解码为Rgba32我们可以根据位深度研究 v3 的更新),因此您将不会捕获图像信息,因为您将 16bpp 信息压缩到8个基点。

Currently you can use Image.Identify(...) to determine the correct bit depth and make intelligent decoding choices, however, given that you know this image is grayscale and has a high dynamic range let's just decode it using L16 ( 16bit single luminance component ) and then stretch the histogram using the newly added method for V3.目前,您可以使用Image.Identify(...)来确定正确的位深度并做出智能解码选择,但是,鉴于您知道该图像是灰度图像并且具有高动态范围,我们只需使用L1616 位单亮度)对其进行解码component ),然后使用 V3 新添加的方法拉伸直方图。 https://github.com/SixLabors/ImageSharp/pull/2235 https://github.com/SixLabors/ImageSharp/pull/2235

using Image<La16> image = Image.Load<La16>(...);
image.Mutate(x => x.HistogramEqualization(new()
{
    LuminanceLevels = 65536,
    Method = HistogramEqualizationMethod.AutoLevel
}));
image.SaveAsPng(...)

The result is as expected.结果符合预期。

DecodeMystery_L16_mystery

PM> Install-Package SixLabors.ImageSharp -Version 3.0.0-alpha.0.52 -Source https://www.myget.org/F/sixlabors/api/v3/index.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM