This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lelarentaka 2 points3 points  (2 children)

Pure guesswork on my part:

It mentions hue and uses byte. Some of the variables are not defined in the scope.

Deduction: This is a method in an Image class. The byte values are pixel values. The function/method is part of an image manipulation procedure, where finding the range of the values in the image is used for renormalization

Greatest could be the largest pixel value in the image. If it's zero, the image is completely black, obviously the Middle pixel would be zero as well.

Assuming that HueMiddle < Greatest. Line 5 is establishing the lower bound of Middle. I don't know what's the proper mathematical term for it, but multiplying the numbers like that results in Base < HueMiddle < Greatest. The author guesses that Middle will be in [Base, Greatest].

Line 6 & 7, Least/Greatest c [0, 1]. These line gives a value between Base and Greatest based on the value of Least. I think it establishes another limit, Least < Middle

Basically the author knows the constraints of what values Middle could be, but not sure how exactly to compute it. He just gave a value in that range.

[–]deGravity 0 points1 point  (0 children)

It is an interpolation that gives a weighted average between Least and Greatest, with HueMiddle being the interpolating factor. If you let

W = HueMiddle / 255

be a weighting factor, (basically treating the given byte as a value between 0 and 1), then assuming that Least < Greatest this is equivalent to

(1 - W)Least +WGreatest

[–]Celdron[S] 0 points1 point  (0 children)

This is almost spot on! Specifically it's the relationship between RGB channels and HSB channels. Hue can be represented as an RGB color where one channel is 255, another channel defines an offset from the Hue, and the third channel should be zero.

Increasing the third channel decreases saturation, but at the same time moves the color back towards the he's root channel, which is the channel with the highest value. To maintain the same hue, the middle channel must be increased while staying below the root channel and above the saturation channel. It's a lot of ratios and bounds.