Is there a way to truncate and normalize an image in one step?
e.g. linearly map values from 50-100 to 0-255 ?
I can do it manually but of course its slow...
byte range = (byte) (UpperThreshold - LowerThreshold);
double f = (1.0 / (double) range) * 255;
var copy = scan.Clone();
for (int x = 0; x < copy.Cols; x++) {// todo this needs to be in native openCV to be fast enough for use
for (int y = 0; y < copy.Rows; y++) {
byte v = copy.At<byte>(y, x);
double d = v;
d = (d - LowerThreshold) * f;
if (d < 0) d = 0;
if (d > 255) d = 255;
v = (byte) d;
copy.Set<byte>(y,x,v);
}
}
return copy;