POV-Ray : Newsgroups : povray.binaries.images : An experiment in monochrome : Re: An experiment in monochrome Server Time
25 Apr 2024 08:18:52 EDT (-0400)
  Re: An experiment in monochrome  
From: Bald Eagle
Date: 11 Jun 2021 18:45:00
Message: <web.60c3e71d23b82ed51f9dae3025979125@news.povray.org>
"m@b" <sai### [at] googlemailcom> wrote:

> I was over thinking, maybe this will work:
>
> #declare GreyTest = abs(TestR(X,Y,0)-TestG(X,Y,0)) +
> abs(TestR(X,Y,0)-TestB(X,Y,0)) + abs(TestB(X,Y,0)-TestG(X,Y,0));


I thought a bit about this, underthought it while playing with the idea, and
then realized that what I wanted to suggest was making use of the HSV color
space.

That way when all of the color channels are equal, the Hues cancel each other
out, or if they are close, then they give a small Saturation vector.  You can
then set the threshold and test the length of that Saturation vector.
Brightness would correspond to the Value.

Then you just use the CRGB2HSV color conversion macro in colors.inc (requires
CRGB2H).

// Converts a color in RGB color space to a color in HSV color space.
// Input:  < Red, Green, Blue, Filter, Transmit >
// Output: < Hue, Saturation, Value, Filter, Transmit >
#macro CRGB2HSV(Color)
   #local RGBFT = color Color;
   #local R = (RGBFT.red);
   #local G = (RGBFT.green);
   #local B = (RGBFT.blue);
   #local Min = min(R,min(G,B));
   #local Max = max(R,max(G,B));
   #local Span = Max-Min;
   #local H = CRGB2H (<R,G,B>, Max, Span);
   #local S = 0; #if (Max!=0) #local S = Span/Max; #end
   <H,S,Max,(RGBFT.filter),(RGBFT.transmit)>
#end


// Takes RGB vector, Max component, and Span as input,
// returns Hue value.
#macro CRGB2H (RGB, Max, Span)
   #local H = 0;
   #local R = RGB.red;
   #local G = RGB.green;
   #local B = RGB.blue;
   #if (Span>0)
      #local H = (
         + (R = Max & G != Max ? 0 + (G - B)/Span : 0)
         + (G = Max & B != Max ? 2 + (B - R)/Span : 0)
         + (B = Max & R != Max ? 4 + (R - G)/Span : 0)
      )*60;
   #end
   H
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.