From 936c1f4f9e59b4e2b1bfe66db66b2b492835daf1 Mon Sep 17 00:00:00 2001 From: ariotte <ariotte@PC-EII16.admr.insa> Date: Mon, 2 Jul 2018 13:57:44 +0200 Subject: [PATCH] prepared algorithm for custom pseudo color --- app/Operations/PseudoColorOp.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Operations/PseudoColorOp.cpp b/app/Operations/PseudoColorOp.cpp index feb5b85..6a1eaf4 100644 --- a/app/Operations/PseudoColorOp.cpp +++ b/app/Operations/PseudoColorOp.cpp @@ -33,16 +33,27 @@ bool PseudoColorOp::needCurrentImg() const { return true; } +static int getLinearHue(int value, int nhue){ + return floor(value * nhue / 255); +} + void PseudoColorOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) { - GrayscaleImage* tmpImg = Converter<GrayscaleImage>::convert(*image); - Image* resImg = new Image(tmpImg->getWidth(), tmpImg->getHeight(), 3); + GrayscaleImage* tmpImg = Converter<GrayscaleImage>::convert(*image); + Image* resImg = new Image(tmpImg->getWidth(), tmpImg->getHeight(), 3); + + int nhue = 255; // changer cette valeur en fonction de la fenêtre de dialog + + int (*getHue)(int a, int b); + + getHue = getLinearHue; + for(unsigned int j = 0; j < tmpImg->getHeight(); ++j) { for(unsigned int i = 0; i < tmpImg->getWidth(); ++i) { Image::depth_t value = tmpImg->getPixel(i, j); - const int nhue = 256; - const int ngrad = ceil(256. / (double)nhue); - const int hue = floor(value * nhue / 256); /* € [0, nhue[ */ - const int grad = value - ceil((double)hue * 256. / (double)nhue); /* € [0, ngrad[ */ + + const int ngrad = ceil(255. / (double)nhue); + const int hue = getHue(value, nhue); /* € [0, nhue[ */ + const int grad = value - ceil((double)hue * 255 / (double)nhue); /* € [0, ngrad[ */ QColor color = QColor::fromHsl(300 - hue * 300 / nhue, 255, (grad + 1) * 255 / (ngrad + 1)); resImg->setPixel(i, j, 0, color.red()); resImg->setPixel(i, j, 1, color.green()); -- GitLab