-
-
Notifications
You must be signed in to change notification settings - Fork 888
Fix edge detection and reenable entropy crop tests #1145
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1145 +/- ##
==========================================
+ Coverage 82.27% 82.29% +0.01%
==========================================
Files 679 680 +1
Lines 29274 29301 +27
Branches 3278 3279 +1
==========================================
+ Hits 24085 24112 +27
Misses 4500 4500
Partials 689 689
Continue to review full report at Codecov.
|
|
I tried to follow the discussions under #1143, but maybe missed a few points. What is the main reason you've chosen this vs premultiplication? I wonder how does OpenCV or ImageMagic work for images with alpha. @dlemstra do you know or can you quickly check it? |
| PixelOperations<TPixel>.Instance.ToVector4(this.configuration, targetRowSpan.Slice(0, span.Length), span, PixelConversionModifiers.Scale); | ||
| ref Vector4 baseRef = ref MemoryMarshal.GetReference(span); | ||
|
|
||
| for (int x = 0; x < this.bounds.Width; x++) | ||
| { | ||
| ref Vector4 v = ref Unsafe.Add(ref baseRef, x); | ||
| v.W = 1F; | ||
| } | ||
|
|
||
| PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, span, targetRowSpan, PixelConversionModifiers.Scale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet another place where an extended PixelTypeInfo would be super useful to eliminate unnecessary scanning. Related discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup.
|
@antonfirsov We do use premultiplication but then reassign the alpha value from the source before unpremultiplying. If you don't do that you end up with a blank image if you have a consistent alpha channel. Basically the only thing I changed was to normalize the alpha component before the algorithm runs. OpenCV does the same. In the link you can see it's picking up changes that would not exist without removing the alpha component first. PIL doesn't do this and will produce an entirely transparent image. (However in that closed issue they've misidentified the result as having a zero alpha channel, when, in fact, the image has no information in any channels. |
antonfirsov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small naming suggestion, otherwise LGTM.
|
|
||
| namespace SixLabors.ImageSharp.Processing.Processors.Filters | ||
| { | ||
| internal sealed class OpaqueProcessor<TPixel> : ImageProcessor<TPixel> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be MakeOpaqueProcessor better? (Related extension to be added later: image.MakeOpaque().)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that if/when we choose to expose such an extension.
Prerequisites
Description
Edge detection now produces fully opaque output. This stabilizes the output across platforms and also fixes entropy cropping.