Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Edge detection now produces fully opaque output. This stabilizes the output across platforms and also fixes entropy cropping.

@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone Mar 14, 2020
@JimBobSquarePants JimBobSquarePants requested a review from a team March 14, 2020 06:56
@codecov
Copy link

codecov bot commented Mar 14, 2020

Codecov Report

Merging #1145 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
#unittests 82.29% <100.00%> (+0.01%) ⬆️
Impacted Files Coverage Δ
...essors/Convolution/ConvolutionProcessor{TPixel}.cs 77.77% <100.00%> (ø)
...ors/Convolution/EdgeDetector2DProcessor{TPixel}.cs 100.00% <100.00%> (ø)
...onvolution/EdgeDetectorCompassProcessor{TPixel}.cs 95.55% <100.00%> (+0.31%) ⬆️
...ssors/Convolution/EdgeDetectorProcessor{TPixel}.cs 100.00% <100.00%> (ø)
...sing/Processors/Filters/OpaqueProcessor{TPixel}.cs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ffdc47...c0585b3. Read the comment docs.

@antonfirsov
Copy link
Member

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?

Comment on lines +54 to +63
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);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup.

@JimBobSquarePants
Copy link
Member Author

@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.

Copy link
Member

@antonfirsov antonfirsov left a 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>
Copy link
Member

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().)

Copy link
Member Author

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.

@JimBobSquarePants JimBobSquarePants merged commit 7ea5c4e into master Mar 15, 2020
@JimBobSquarePants JimBobSquarePants deleted the js/fix-detect-edges branch March 15, 2020 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants