Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GaussianBlur does not work with I;16 #6667

Open
amdepott opened this issue Oct 17, 2022 · 10 comments
Open

GaussianBlur does not work with I;16 #6667

amdepott opened this issue Oct 17, 2022 · 10 comments

Comments

@amdepott
Copy link

amdepott commented Oct 17, 2022

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
@radarhere
Copy link
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;*.

@radarhere radarhere changed the title ImageFilter does not work with 16-bit images ImageFilter does not work with I or I;16 Oct 21, 2022
@radarhere
Copy link
Member

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

@radarhere radarhere changed the title ImageFilter does not work with I or I;16 ImageFilter does not work with I;16 May 3, 2023
@GrayMask
Copy link

GrayMask commented Jan 10, 2024

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?

@radarhere
Copy link
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?

@GrayMask
Copy link

GrayMask commented Jan 10, 2024

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.

@radarhere
Copy link
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.

@GrayMask
Copy link

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!

@homm
Copy link
Member

homm commented Jan 11, 2024

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.

@amdepott amdepott reopened this Aug 27, 2024
@amdepott
Copy link
Author

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

@radarhere
Copy link
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.

@radarhere radarhere changed the title ImageFilter does not work with I;16 GaussianBlur does not work with I;16 Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants