Job Job::execute() { int width = this->originalImage.columns(); int height = this->originalImage.rows(); std::vector<double> luminosities; int i, j; for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { Magick::ColorHSL pixelColor = originalImage.pixelColor(i, j); double pixelLuminosity = pixelColor.luminosity(); luminosities.push_back(pixelLuminosity); } } std::sort(luminosities.begin(), luminosities.end()); int cutoff = (int) (width * height * percentage) / 100; double threshold = luminosities[cutoff]; Magick::Image processedImage(Magick::Geometry(width, height), "white"); this->processedImage = processedImage; for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { Magick::ColorHSL pixelColor = originalImage.pixelColor(i, j); double pixelLuminosity = pixelColor.luminosity(); this->processedImage.pixelColor(i, j, Magick::ColorMono(pixelLuminosity > threshold)); } } return *this; }
/*void ProcessImage::ReadGrayImage(const Image& image, vector<REAL>&pixval) { UINT m = image.rows(), n = image.columns(); ColorGray mycolor; UINT count = 0; for (UINT i = 0; i < m; ++i) { for (UINT j = 0; j < n; ++j) { ColorGray mycolor = image.pixelColor(j, i); pixval[count++] = mycolor.shade(); } } }*/ void ProcessImage::ReadHSLImage(const Image &image, vector<REAL>&h, vector<REAL>&s, vector<REAL>&l) { int count = 0; for (unsigned int row = 0; row < image.rows(); row++) { for (unsigned int col = 0; col < image.columns(); col++, ++count) { Magick::Color pixCol = image.pixelColor(col, row); Magick::ColorHSL hslPixCol = Magick::ColorHSL(pixCol); // white: 0.0h 0.0s 1.0l, black: 0.0h 0.0s 0.0h h[count] = hslPixCol.hue(); s[count] = hslPixCol.saturation(); l[count] = hslPixCol.luminosity(); } } }