Skip to content

GaussianBlur does not work with I;16 #6667

Description

@amdepott

What did you do?

Attempted to use Image.filter(ImageFilter.BLUR) on an image of mode I or I;16

What did you expect to happen?

Image is blurred

What actually happened?

Code throws ValueError

What are your OS, Python and Pillow versions?

  • OS: Windows 10 Home
  • Python: 3.10.1
  • Pillow: 9.2.0
>>> from tkinter import filedialog
>>> from PIL import Image, ImageFilter
>>> image1 = Image.open(filedialog.askopenfilename())
>>> image1
   <PIL.BmpImagePlugin.BmpImageFile image mode=RGB size=630x514 at 0x28B7051E9B0>
>>> image2 = image1.convert('I')
>>> image2
   <PIL.Image.Image image mode=I size=630x514 at 0x28B70A8E560>
>>> image1.filter(ImageFilter.BLUR).show()
>>> image2.filter(ImageFilter.BLUR).show()
   Traceback (most recent call last):
     File "<pyshell#56>", line 1, in <module>
       image2.filter(ImageFilter.BLUR).show()
     File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 1247, in filter
       return self._new(filter.filter(self.im))
     File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\ImageFilter.py", line 32, in filter
       return image.filter(*self.filterargs)
   ValueError: image has wrong mode

Activity

  1. radarhere commented on Oct 17, 2022

    @radarhere
    Member

    Just an explanation from the code.

    ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32 *kernel, FLOAT32 offset) {
    Imaging imOut;
    ImagingSectionCookie cookie;
    if (!im || im->type != IMAGING_TYPE_UINT8) {
    return (Imaging)ImagingError_ModeError();
    }

    means that it doesn't support I, I;*, F or BGR;*.

  2. changed the title [-]ImageFilter does not work with 16-bit images[/-] [+]ImageFilter does not work with I or I;16[/+] on Oct 21, 2022
  3. radarhere commented on May 3, 2023

    @radarhere
    Member

    PR #7108 has been merged, fixing this for I mode.

  4. changed the title [-]ImageFilter does not work with I or I;16[/-] [+]ImageFilter does not work with I;16[/+] on May 3, 2023
  5. GrayMask commented on Jan 10, 2024

    @GrayMask

    Hi!
    When I use ImageFilter to performs a look-up table (LUT) transform on an image of mode I or I;16,

    File ".../PIL/ImageFilter.py", line 560, in filter
        return image.color_lut_3d(
    ValueError: image has wrong mode
    

    still occurred.

    I found that I mode has been supported for BuiltinFilter but still not supported for Color3DLUT.
    Related code:
    https://github.com/python-pillow/Pillow/blob/main/src/libImaging/ColorLUT.c#L89-L92

    Would mode I be supported for Color3DLUT in the future?

  6. radarhere commented on Jan 10, 2024

    @radarhere
    Member

    Screenshot 2024-01-10 at 8 10 24 pm

    I don't see how a function that "transforms 3-channel pixels" applies to a 1 channel image.

    Could you describe in more detail what you are trying to do?

  7. GrayMask commented on Jan 10, 2024

    @GrayMask

    Thanks for your reply.

    I'm sorry, I misunderstood.
    I thought mode I supported 3-channel 32-bit images, however it only supports 1-channel.

    I am trying to perform a look-up table (LUT) transform on heif images which are in 10-bit & 3-channel.
    Now I find that Pillow only supports 8-bit color depth for 3-channel images (<- Am I right?), so the only way is to convert the 10-bit images to 8-bit in advance, even though it will reduce the amount of color information.

  8. radarhere commented on Jan 10, 2024

    @radarhere
    Member

    Now I find that Pillow only supports 8-bit color depth for 3-channel images

    Yes, see #1888

    so the only way is to convert the 10-bit images to 8-bit in advance, even though it will reduce the amount of color information.

    If your goal is to use the final image with Pillow, then yes.
    If your goal is to use the final image with something else, then I suppose you would split 10-bit 3-channel images to 3 10-bit 1-channel images in advance, then use Pillow to handle the LUT, and then merge the images again outside of Pillow.

  9. GrayMask commented on Jan 10, 2024

    @GrayMask

    If your goal is to use the final image with something else, then I suppose you would split 10-bit 3-channel images to 3 10-bit 1-channel images in advance, then use Pillow to handle the LUT, and then merge the images again outside of Pillow.

    Oh! Thanks for your suggestion!

  10. homm commented on Jan 11, 2024

    @homm
    Member

    split 10-bit 3-channel images to 3 10-bit 1-channel images in advance, then use Pillow to handle the LUT

    Again, this wouldn't 3D LUT, this will be three 1D LUTs.

  11. amdepott commented on Aug 27, 2024

    @amdepott
    Author

    Still does not work on I;16
    Also does not work with gaussian blur filters

  12. radarhere commented on Oct 10, 2024

    @radarhere
    Member

    #8438 has been merged to support I;16 modes with ImageFilter.BLUR. Pillow 11 is due to be released in a week with this feature.

  13. changed the title [-]ImageFilter does not work with I;16[/-] [+]GaussianBlur does not work with I;16[/+] on Oct 10, 2024
  14. akx commented on Jul 7, 2026

    @akx
    Contributor

    @radarhere I think this can be closed, since Pillow 11 was released a while ago. #9760 will speed up #8438 though.

  15. radarhere commented on Jul 7, 2026

    @radarhere
    Member

    I don't think so, because GaussianBlur still isn't supported.

    >>> from PIL import Image, ImageFilter
    >>> im = Image.new("I;16", (1, 1))
    >>> im.filter(ImageFilter.GaussianBlur)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "IL/Image.py", line 1458, in filter
        return self._new(filter.filter(self.im))
      File "PIL/ImageFilter.py", line 206, in filter
        return image.gaussian_blur(xy)
    ValueError: image has wrong mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions