0

I installed OpenCV in my Windows OS and successfully configure a correpond Visual Studio project. But when I use imread to read a tiff image file, the Mat object would be empty. If I convert the file to bmp format, the program works. I wonder how can OpenCV do tiff I/O in windows.

My OpenCV version is 2.4.13 and I am using VS 2013.

After running "magick identify", the output is:

Image: TBAL2015032700100902012.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 2502x1505+0+0
Resolution: 300x300
Print size: 8.34x5.01667
Units: PixelsPerInch
Type: TrueColor
Endianess: LSB
Colorspace: sRGB
Depth: 8-bit
Channel depth:
  Red: 8-bit
  Green: 8-bit
  Blue: 8-bit
Channel statistics:
  Pixels: 3765510
  Red:
    min: 0  (0)
    max: 255 (1)
    mean: 199.179 (0.781094)
    standard deviation: 44.2111 (0.173377)
    kurtosis: 9.97873
    skewness: -3.17169
    entropy: 0.774441
  Green:
    min: 0  (0)
    max: 255 (1)
    mean: 204.13 (0.800508)
    standard deviation: 41.8485 (0.164112)
    kurtosis: 9.24617
    skewness: -3.00098
    entropy: 0.77394
  Blue:
    min: 0  (0)
    max: 255 (1)
    mean: 156.85 (0.615098)
    standard deviation: 41.3859 (0.162298)
    kurtosis: 1.57158
    skewness: -1.13336
    entropy: 0.89716
Image statistics:
  Overall:
    min: 0  (0)
    max: 255 (1)
    mean: 186.72 (0.732233)
    standard deviation: 47.5017 (0.186281)
    kurtosis: 3.30247
    skewness: -1.81231
    entropy: 0.81518
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)
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 2502x1505+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Orientation: TopLeft
Properties:
  comment:                                                                                                            
  date:create: 2017-12-08T16:15:53+08:00
  date:modify: 2015-03-27T10:25:22+08:00
  jpeg:sampling-factor: 2x1
  signature: 70f8c75014e79eb786765d727ccb564688c3da3c3d5f9f0b4c56f259e2d88625
  tiff:alpha: unspecified
  tiff:artist: SysAdmin
  tiff:document: DN0P46158952        0000000022000000053700000.----!--
  tiff:endian: lsb
  tiff:make: Eastman Kodak
  tiff:model: Kodak Scanner: i1405
  tiff:photometric: YCBCR
  tiff:rows-per-strip: 1505
  tiff:software: KODAK Capture Desktop 1.2
  tiff:timestamp: 2015.03.27 10:25:22
Artifacts:
  verbose: true
Tainted: False
Filesize: 619460B
Number pixels: 3765510
Pixels per second: 83.6779MB
User time: 0.047u
Elapsed time: 0:01.045
Version: ImageMagick 7.0.7-14 Q16 x64 2017-12-06 http://www.imagemagick.org
JTT
  • 109
  • 4
  • 14
  • 1
    try `Mat image = imread("image.tiff", IMREAD_UNCHANGED);` and see whether it fix the problem. Your image may have 4 channels. – lamandy Dec 13 '17 at 05:59
  • If that does not fix the problem, have a look at this [link](https://stackoverflow.com/questions/22334069/opencv-2-4-5-unable-to-load-tif-image-file-properly-in-windows?rq=1), it seems like it has something to do with the encoding. – lamandy Dec 13 '17 at 06:07
  • As a workaround, you could convert the `TIF`s to, say `PNG` files, at the Command Prompt with **ImageMagick**. Command would be `magick input.tif output.png`. Or, if you don't need the metadata, use a `PPM` format which **OpenCV** can read without libraries `magick input.tif output.ppm` – Mark Setchell Dec 13 '17 at 07:41
  • Try running `magick identify -verbose yourImage.tif` and pasting the output into your question (click `edit` under question). Maybe someone will see what is upsetting **OpenCV** - it could be non-standard compression, an alpha channel, a pyramid... – Mark Setchell Dec 13 '17 at 07:55
  • @MarkSetchell using the flag "IMREAD_UNCHANGED" didn't help. – JTT Dec 13 '17 at 09:04
  • That was not my suggestion ;-) – Mark Setchell Dec 13 '17 at 09:07
  • I wonder if the `Photometric Interpretation` is what is upsetting **OpenCV**, as it is `tiff:photometric: YCBCR` which is not that common. Maybe you could try deleting that tag and using `cvtColor(COLOR_YCrCb2RGB)` or similar and reordering channels. – Mark Setchell Dec 13 '17 at 09:07
  • There is a tool called `tiffset` that comes with `libtiff` (IIRC). You can maybe try resetting the `Photometric Interpretation` and seeing if **OpenCV** can read it then. https://www.awaresystems.be/imaging/tiff/tifftags/baseline.html and https://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.html So, it might be something like `tiffset -s 262 2 YourFile.tif` – Mark Setchell Dec 13 '17 at 09:17
  • So I couldn't solve the problem inside OpenCV?@MarkSetchell – JTT Dec 13 '17 at 12:28
  • I convert the image to bmp and convert it back to tiff with "Microsoft Paint". And OpenCV can read that file. I compare two tiff file's Magick metadata. The original tiff file has a additional alpha channel.@MarkSetchell – JTT Dec 13 '17 at 12:30
  • How can I delete that tag? The Mat object I get from imread is empty.@MarkSetchell – JTT Dec 13 '17 at 12:32
  • You ran `magick identify` on the wrong image then? Because the information you posted is not from a TIFF with an alpha channel. How about sharing the troublesome TIFF file? – Mark Setchell Dec 13 '17 at 15:12
  • You can change the `Photometric Interpretation` flag using `tiffset` like I said in my earlier comment. – Mark Setchell Dec 13 '17 at 15:12
  • @MarkSetchell Yes I was wrong, the converted image have alpha channel, and the original image doen't – JTT Dec 14 '17 at 05:31
  • @MarkSetchell How can I install tiffset in Windows? – JTT Dec 14 '17 at 05:41
  • @MarkSetchell I found it. I run tiffset on my original tiff file and I got "ori.tif: JPEG compression support is not configured." – JTT Dec 14 '17 at 05:48

0 Answers0