-
Notifications
You must be signed in to change notification settings - Fork 4
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
downsample the image before clustering #71
Conversation
Codecov Report
@@ Coverage Diff @@
## master #71 +/- ##
==========================================
+ Coverage 98.44% 98.49% +0.04%
==========================================
Files 14 14
Lines 257 265 +8
==========================================
+ Hits 253 261 +8
Misses 4 4
Continue to review full report at Codecov.
|
This commit also adds ImageBase dependency; a drop-in replacement for ImageCore with a few handy operators.
src/clustering.jl
Outdated
# Clustering on the downsampled image already generates good enough colormap estimation | ||
# This significantly reduces the algorithmic complexity. | ||
img = _restrict_to(img, ncolors*100) | ||
data = convert(Array{Float32}, reshape(channelview(Lab.(img)), 3, :)) |
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.
Is there a reason for the added conversion?
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.
For many big-data problems, it's often a good strategy to eagerly collect data into a contiguous memory layout so that future slicing on data[inds...]
can be faster.
I added this before trying the downsample trick only to verify if this helps reduce the allocations. Here I don't observe any performance difference, I guess it's because Clustering.jl is doing a similar thing on their side.
I've reverted this in the new commit.
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.
Looks great, good idea!
For any real-world image, clustering the image pixel is a computational intensive big-data problem. For our very purpose to estimate the colormap, a downsampled
the version already works well.
The results are not identical but the visual quality looks quite similar. I think this is a good improvement overall (not a breaking change).