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

Fast filters #2679

Merged
merged 21 commits into from
Sep 10, 2017
Merged

Fast filters #2679

merged 21 commits into from
Sep 10, 2017

Conversation

homm
Copy link
Member

@homm homm commented Aug 12, 2017

               Ubuntu 14.04    i2f or 16.04       Optimized
Smooth        12.47 Mpx/s     28.81 Mpx/s       44.71 Mpx/s
Sharpen       12.34 Mpx/s     29.94 Mpx/s       44.74 Mpx/s
Smooth More    4.41 Mpx/s     12.49 Mpx/s       17.61 Mpx/s

PIL/Image.py Outdated
@@ -1112,7 +1112,9 @@ def filter(self, filter):
raise TypeError("filter argument should be ImageFilter.Filter " +
"instance or class")

if self.im.bands == 1:
multiband = getattr(filter, 'is_multiband', False)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All filters used to work only with single-channel images. As this is public API and there are can be custom filters in a wild, we can't just send multi-channel images to all filters. So is_multiband flag indicates that the filter is ready for multi-channel images.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wiredfool As of naming things is one of the hard problems in programming, I need your help there )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a reasonable name, at least, I haven't thought of anything better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The another option is subclass MultibandFilter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably cleaner, especially with an eye towards the typing PR.

@@ -852,8 +852,12 @@ _filter(ImagingObject* self, PyObject* args)
return ImagingError_ValueError("bad kernel size");
}

for (i = 0; i < kernelsize; ++i) {
kerneldata[i] /= divisor;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precompute by dividing coefficients to divisor rather than each result pixel.

@homm homm added this to the 4.3.0 milestone Aug 12, 2017
@homm
Copy link
Member Author

homm commented Aug 13, 2017

Oh my god! I clash with the same bug in Intel x64 CPUs with int to float conversion, as I did when was working on resampling for Pillow 2.7.

In essence: GCC version < 4.9 (at least Ubuntu 14.04, Debian 7 Wheezy, Red Hat Linux 7) generates code which runs about 2.5 times slower than GCC >= 4.9. This can be fixed using ugly hack with assembler. We decided to include this hack in Pillow 2.7 (released Jan 1, 2015). After rewriting the resampling using fixed point arithmetics, this hack become obsolete and was removed in Pillow 3.3 (Jul 1, 2016). Unlike for resampling, I don't see a way to implement kernel filters on FPA. So, I suggest to include this hack again.

@homm
Copy link
Member Author

homm commented Aug 13, 2017

I've just tried SSE4 for multiband images, with no specific optimizations some optimizations.

                Simple SSE4     Optimized SSE4    OpenCV
Smooth         137.25 Mpx/s    192.01 Mpx/s      163.68 Mpx/s
Sharpen        133.55 Mpx/s    171.32 Mpx/s      163.81 Mpx/s
Smooth More     45.71 Mpx/s     69.34 Mpx/s       64.01 Mpx/s

@homm homm removed the Needs Tests label Aug 15, 2017
@homm
Copy link
Member Author

homm commented Sep 10, 2017

@wiredfool implemented through MultibandFilter

@wiredfool wiredfool merged commit 3b5c2c3 into python-pillow:master Sep 10, 2017
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

Successfully merging this pull request may close these issues.

2 participants