Giter Club home page Giter Club logo

palette-pick's People

Contributors

jackieh avatar

Watchers

 avatar  avatar

Forkers

cowile

palette-pick's Issues

Results of get_hue_spread_colors are discarded.

I saw the results of the hue spread method are not noticeably different from a random spread. I followed this in the code and found a likely bug.

Before being passed into find_clusters, sample_colors is initialized with get_hue_spread_colors. But sample_colors is an output parameter that is cleared by find_clusters, meaning the initialization changes nothing.

case ImageGetSampleColorsMode::Value::kmeans_hue_spread:
sample_colors = get_hue_spread_colors(num_colors);
success = ColorKMeans::find_clusters(
num_colors, ColorKMeans::SeedMode::keep_existing,
get_unique_colors(), sample_colors);
break;
case ImageGetSampleColorsMode::Value::kmeans_bright_hue_spread: {
const std::vector<Color> unique_colors = get_unique_colors();
std::vector<Color> data_colors = get_bright_colors(unique_colors);
sample_colors = get_hue_spread_colors(num_colors);
success = ColorKMeans::find_clusters(
num_colors, ColorKMeans::SeedMode::keep_existing,
data_colors, sample_colors);
break;
}
case ImageGetSampleColorsMode::Value::kmeans_saturated_hue_spread: {
const std::vector<Color> unique_colors = get_unique_colors();
std::vector<Color> data_colors =
get_saturated_colors(unique_colors);
sample_colors = get_hue_spread_colors(num_colors);
success = ColorKMeans::find_clusters(
num_colors, ColorKMeans::SeedMode::keep_existing,
data_colors, sample_colors);
break;

color_centroids.clear();

mkstripes loop is O(n^2) when it could be O(n)

Instead of partitioning the canvas into separate rectangles to fill, this loop fills progressively smaller overlapping rectangles. This results in the loop being quadratic to the number of pixels rather than linear.

After profiling, making the loop linear results in an 8.8x speedup in the mkstripes program.

for (const auto &stripe_color : stripe_colors_.get()) {
stripes.fillColor(stripe_color.get());
int stripe_width_begin = stripe_idx * stripe_width_;
switch (stripe_orientation_.get()) {
case Orientation::Value::vertical:
stripes.draw(Magick::DrawableRectangle(
stripe_width_begin, 0,
image_width, image_height));
break;
case Orientation::Value::horizontal:
stripes.draw(Magick::DrawableRectangle(
0, stripe_width_begin,
image_width, image_height));
break;
default:
error_stream << "Unknown stripes orientation" << std::endl;
return false;
}
++stripe_idx;
}

Initialization loop is pointless.

Because color_centroids was cleared before the loop, size will always be zero so c will never be less than.

The rest of the loop initializes all matrix elements to zero. armadillo offers a zeros function to return a zero matrix directly. That should be used instead of eye.

arma::mat means = arma::eye(3, num_clusters);
for (size_t c = 0; c < num_clusters; ++c) {
if (c < color_centroids.size()) {
const Color &color = color_centroids.at(c);
means(0, c) = static_cast<int>(color.get().quantumRed());
means(1, c) = static_cast<int>(color.get().quantumGreen());
means(2, c) = static_cast<int>(color.get().quantumBlue());
} else {
means(0, c) = 0;
means(1, c) = 0;
means(2, c) = 0;
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.