float dist(const Indiv& ind) { cv::Mat tmp(ind.image()); assert(tmp.cols == _image.cols); assert(tmp.rows == _image.rows); float total_distance = 0; // Change specific color of every pixel in the image for (int x = 0; x < tmp.cols; ++x) { for (int y = 0; y < tmp.rows; ++y) { cv::Vec3b color_2 = _image.at<cv::Vec3b>(cv::Point(x,y)); // cv::Vec3b color_1 = tmp.at<cv::Vec3b >(cv::Point(x,y)); // Three color values H, S, L for (int c = 0; c < 3; c++) { float d = color_1[c] - color_2[c]; total_distance += d * d; // Add the square of this distance } } } return sqrtf(total_distance); }
void eval(const Indiv& ind) { if (Params::image::color) { // Convert image to BGR before evaluating cv::Mat output; // Convert HLS into BGR because imwrite uses BGR color space cv::cvtColor(ind.image(), output, CV_HLS2BGR); // Create an empty list to store get 1000 probabilities _setProbabilityList(output); } else // Grayscale { // Create an empty list to store get 1000 probabilities _setProbabilityList(ind.image()); } }