How can I get the bands of a .tiff UAV image using tifffile?

I have a .tiff UAV image and I need to get the R,G,B bands with georeferencing using tifffile. Any idea how do I achieve this?

this? tifffile · PyPI
or that (which is the above)? Module: external.tifffile — skimage v0.14.3 docs

1 Like

I managed to get the 3 bands of the UAV .tiff and did some calculations (such as result = Green/ Red) with rasterio. But when I try to open the new .tif image I get this error:

    self.img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(3.4.14) /tmp/pip-req-build-m7h7rfem/opencv/modules/imgproc/src/color.simd_helpers.hpp:88: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<3, 4>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Invalid number of channels in input image:
>     'VScn::contains(scn)'
> where
>     'scn' is 1

Any idea how to fix this?
The new .tif has only one channel! And I use PyQt to display it…

that means frame is single-channel.

why is it single-channel?

why do you expect it to be BGR?

1 Like

Sometimes I open RGB tif images, sometimes 4-channels tif images and sometimes 1-channel tif images…How can I achieve that?

check the .shape (height, width, channels), do stuff according to situation

1 Like

Ok, so how do I make it accept 1-band tiff images? Which is the suitable flag?

that would require the source data to be BGR, i.e. 3-channel.

if you don’t have 3-channel data, you shouldn’t expect that color conversion code to work.

if you have 1-channel data instead, use a different color conversion code… perhaps one that reads like “gray to …”

1 Like

The code I use is from google search/github. I don’t want to do any color conversion, just show the image on the PyQt window, either 4-band, 1-band, 3-band. I do not want to do any color conversion…Any ideas?

okay, so what formats does Qt like and how do you give the data to Qt?

1 Like
  1. It reads RGBA and gray scale. I choose the file from a open file button.
  2. I read the channels like this: height, width, channels = np.shape(tifimage) When I load 4-band .tif image everything ok. When I load 1-band .tif image I get an error when I try to read channels variable…because channels variable gets nothing…How can I avoid that?
if len(tifimage.shape) == 2:
    (height, width) = tifimage.shape
    channels = 1
    (height, width, channels) = tifimage.shape
1 Like

Hello! Thanks! I get this error, any ideas??

   if len(tifimage.shape) == 2:
AttributeError: 'NoneType' object has no attribute 'shape'

the image is empty. why is it empty?

The image is not empty. I have just tested with QGIS and opens perfectly. However with the above code does not open, and when I check the shape (with another python code) it gives me only height and width and nothing/null for channels…

that literally means tifimage was None

only you know why. I can’t see the code.

1 Like

This is the info of the .tif image I am trying to open:

Band 1 Block=7421x1 Type=Float64, ColorInterp=Gray

Do you see anything wrong?

The .tif that I have the problem is float64. Has anything to do with this?