WesleyyC / Image-Editor

A command line image editor written in Java
MIT License
3 stars 0 forks source link

Add darken function. #8

Open WesleyyC opened 9 years ago

WesleyyC commented 9 years ago

Brighten function.

SerinaTan commented 9 years ago

So is there any free and magic function we can use like the brighten function :p ?

SerinaTan commented 9 years ago

Never mind. So it can be done in the same fashion as brighten function. I was trying to figure out what your numbers mean here:

double factor = 1.17 + level * 0.03;
double onset = 12 + 3 * level;

RescaleOp rescaleOp = new RescaleOp((float)factor, (int)onset, null);

It doesn't make sense to me why you would add an offset in the brighten function. I think the offset is just for tinting images (yell at me if it is not). And the scale factor you pass in looks really magical... Would you please give some more explanations?

WesleyyC commented 9 years ago

@SerinaTan
So we are really just adjusting the element value using RescaleOp and the pseudo code for the rescaling operation is as follows:

for each pixel from Source object {
    for each band/component of the pixel {
        dstElement = (srcElement*scaleFactor) + offset
    }
}

The number is really just magic, I adjust the number by manually testing since I can't really find a great comprehensive documentation on these values.

For darken function, we can definitely judge if the level is negative or positive and apply a different function.