简体   繁体   中英

viewing a tif image file using OpenCV in Jupyter notebook

I have a thermal image in TIF format which I can see using display command in Ubuntu. I also have the following information from the image file:

$ file Rec-000026_16bit_counts.tif
Rec-000026_16bit_counts.tif: Big TIFF image data, little-endian
$ exiv2 Rec-000026_16bit_counts.tif
File name       : Rec-000026_16bit_counts.tif
File size       : 2097433 Bytes
MIME type       : 
Image size      : 0 x 0
Rec-000026_16bit_counts.tif: No Exif data found in the file

also

$  tiffinfo Rec-000026_16bit_counts.tif
TIFF Directory at offset 0x200010 (2097168)
  Image Width: 1024 Image Length: 1024
  Bits/Sample: 16
  Sample Format: unsigned integer
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Planar Configuration: single image plane
  Software: ExaminIR

When I run the following cell:

import cv2
img = cv2.imread("Rec-000026_16bit_counts.tif", cv2.IMREAD_UNCHANGED)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

I get the following error:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-67-2756e499dadf> in <module>
      1 import cv2
      2 img = cv2.imread("Rec-000026_16bit_counts.tif", cv2.IMREAD_UNCHANGED)
----> 3 cv2.imshow('image',img)
      4 cv2.waitKey(0)
      5 cv2.destroyAllWindows()
 
error: OpenCV(3.4.9) /io/opencv/modules/highgui/src/window.cpp:382: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

How should I fix this?

I think the image is not in your directory. Otherwise:

import cv2
img = cv2.imread("thermal-imaging-opportunities.jpg", cv2.IMREAD_UNCHANGED)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

The output is:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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