Home>

I am currently trying to process a multi-page TIFF image (multi-band image BSQ data) using Python, but I have two problems.

The first one can read the image with the following code but cannot display it
The image size is over 200MB. Is it too big a problem?

img = cv2.imreard ("???????. tif")
cv2.imshow ("img", img)

I am trying to extract edges from the image read by the second one, but what should I do in the case of a multi-page TIFF image?

edge = cv2.Canny (img, 100,400)
cv2.imwrite ("??????? _ edge.png", edge)

I'm sorry if it was hard to understand

  • Answer # 1

      

    The first one can read the image with the following code but cannot display it

    cv2.waitKey (0)andcv2.destroyAllWindows ()There seems to be no, so please add it.

      

    I am trying to extract edges from the image read by the second one, but what should I do in the case of a multi-page TIFF image?

    PILofImageSequenceYou can divide each page withnumpy.arrayConvert toCannyIt can be processed.
    Reference: Split multi-page TIFF with Pillow

    from PIL import Image, ImageSequence
    import cv2
    import numpy as np
    # http://www.nightprogrammer.org/wp-uploads/2013/02/multipage_tiff_example.tif
    img_path = 'multipage_tiff_example.tif'
    img = cv2.imread (img_path)
    cv2.imshow ('img', img)
    cv2.waitKey (0)
    cv2.destroyAllWindows ()
    img = Image.open (img_path)
    itr = ImageSequence.Iterator (img)
    img = itr [1] # 2nd page
    img = np.array (img)
    edge = cv2.Canny (img, 100,400)
    cv2.imwrite ('ret.png', edge)