画像処理入門 > 初級編 > 輝度範囲変更

輝度範囲変更


輝度範囲変更
輝度の範囲を設定するプログラムです。
最小値に設定した輝度を0、最大値に設定した輝度を255として画像を生成します。

サンプルプログラム
プログラムはこちら void KidoRange(unsigned char *out, unsigned char *in, int inHeight, int inWidth, int inChannel, unsigned char min, unsigned char max){ int i, j; int index; double tmp; double rate; int range; int widthStep; widthStep = inWidth * inChannel; if(widthStep % 4 != 0){ widthStep = widthStep + 4 - widthStep % 4; } range = abs(max - min); rate = (double)256 / (double)(range + 1); for(i = 0; i < inHeight; ++i){ for(j = 0; j < inWidth; ++j){ index = i * widthStep + j; if(in[index] >= min && in[index] <= max){ tmp = (in[index] - min) * rate; if(tmp > 255){ tmp = 255; } out[index] = tmp; } else if(in[index] < min){ out[index] = 0; } else if(in[index] > max){ out[index] = 255; } } } }