Hi,
I need to apply this formula: (blue channel - red channel) / (blue channel + red channel) to some images. The problem is that this formula ranges from -1 to 1, and i have somehow to offset this range to positive values and map it to a full grayscale from 0 to max of ushort.
I managed to achieve the result by iterating pixel by pixel and applying all the required calculations but i dont think it is efficient and i was wondering if it was possible to do direct calculations between the channels. Something like this:
Is it possible to offset the negative values so that -1 corresponds to 0 and 1 to the maxium quantum range?
I need to apply this formula: (blue channel - red channel) / (blue channel + red channel) to some images. The problem is that this formula ranges from -1 to 1, and i have somehow to offset this range to positive values and map it to a full grayscale from 0 to max of ushort.
I managed to achieve the result by iterating pixel by pixel and applying all the required calculations but i dont think it is efficient and i was wondering if it was possible to do direct calculations between the channels. Something like this:
using(MagickImage img = new MagickImage(imgPath))
{
using(MagickImage imgBlue = img.Separate(Channels.Blue).First())
using (MagickImage imgRed = img.Separate(Channels.Red).First())
{
imgBlue.Write(bluePath);
imgRed.Write(redPath);
}
}
using(MagickImage imgBlue = new MagickImage(bluePath))
using(MagickImage imgRed = new MagickImage(redPath))
{
imgBlue.Composite(imgRed, CompositeOperator.MinusDst);
imgBlue.Write(blue_sub_redPath);
}
using (MagickImage imgBlue = new MagickImage(bluePath))
using (MagickImage imgRed = new MagickImage(redPath))
{
imgBlue.Composite(imgRed, CompositeOperator.Plus);
imgBlue.Write(blue_add_redPath);
}
using (MagickImage imgBlue_add_Red = new MagickImage(blue_add_redPath))
using (MagickImage imgBlue_sub_Red = new MagickImage(blue_sub_redPath))
{
imgBlue_sub_Red.Composite(imgBlue_add_Red, CompositeOperator.DivideDst);
imgBlue_sub_Red.Write(Result_Path);
}
The problem with this is that all negative values are truncated to 0. Is it possible to offset the negative values so that -1 corresponds to 0 and 1 to the maxium quantum range?