📄 windipdoc.cpp
字号:
b = *( m_InputImg + address );
g = *( m_InputImg + address + 1 );
r = *( m_InputImg + address + 2 );
//涝仿 康惑俊 肺弊窃荐甫 利侩窍咯 搬苞 蔼阑 掘澜.
*( m_OutputImg+ address ) = (BYTE)( c * log( 1 + b ) );
*( m_OutputImg+ address + 1 ) = (BYTE)( c * log( 1 + g ) );
*( m_OutputImg+ address + 2 ) = (BYTE)( c * log( 1 + r ) );
}
}
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
void CWinDIPDoc::C3_2_4BitPlaneSlicing(int planeNum)
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
int x, y, gray, address;
for( y = 0; y < iSize.cy; y++ )
{
for( x = 0; x < iSize.cx; x++ )
{
address = BmpAddress( x, y, iSize );
gray = *( m_InputImg + address );
*( m_OutputImg + address ) = BitSlicing( gray, planeNum );
*( m_OutputImg + address + 1 ) = BitSlicing( gray, planeNum );
*( m_OutputImg + address + 2 ) = BitSlicing( gray, planeNum );
}
}
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
int CWinDIPDoc::BitSlicing(int gray, int planeNum)
{
int mask;
if(planeNum == 7)
mask = ((gray / (int)pow(2, planeNum)) * (int)pow(2, planeNum)) * 255;
else
mask = ((gray / (int)pow(2, planeNum) * (int)pow(2, planeNum)) - (gray / (int)pow(2, planeNum + 1) * (int)pow(2, planeNum + 1))) * 255;
return mask;
}
void CWinDIPDoc::C3_3_1HistogramEqualization()
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
IntRGB numPixel[256], mTable[256];
Prob prob[256];
ColorFrequencyCounting( m_InputImg, numPixel, iSize ); //鞍篮 侨伎(拳家)蔼狼 肮荐甫 季促
ColorProbability( numPixel, prob, iSize ); // 犬伏阑 备窃
ColorInterval( prob ); //history equalization阑 窃
ColorMappingTable( prob, mTable );
ColorMapping( m_InputImg, m_OutputImg, mTable, iSize );
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
void CWinDIPDoc::ColorFrequencyCounting(BYTE *input, IntRGB numPixel[], CSize iSize)
{
int x, y, b, g, r, gray;
int address;
for( gray = 0; gray < 256; gray++ )
{
numPixel[gray].b = 0;
numPixel[gray].g = 0;
numPixel[gray].r = 0;
}
for( y = 0; y < iSize.cy; y++ )
{
for( x = 0; x < iSize.cx; x++ )
{
address = BmpAddress( x, y, iSize );
b = *( input + address );
g = *( input + address + 1 );
r = *( input + address + 2 );
numPixel[b].b += 1;
numPixel[g].g += 1;
numPixel[r].r += 1;
}
}
}
void CWinDIPDoc::ColorProbability(IntRGB numPixel[], Prob prob[], CSize iSize)
{
int gray;
double size;
size = iSize.cx * iSize.cy;
for(gray = 0; gray < 256; gray++ )
{
prob[gray].b = (double)numPixel[gray].b / size;
prob[gray].g = (double)numPixel[gray].g / size;
prob[gray].r = (double)numPixel[gray].r / size;
}
}
void CWinDIPDoc::ColorInterval(Prob prob[])//??
{
int gray;
for(gray = 0; gray < 256; gray++ )
{
prob[gray].b *= 255.0;
prob[gray].g *= 255.0;
prob[gray].r *= 255.0;
}
}
void CWinDIPDoc::ColorMappingTable(Prob prob[], IntRGB mTable[])
{
int gray;
double sumR, sumG, sumB ;
sumB = 0.0;
sumG = 0.0;
sumR = 0.0;
for(gray = 0; gray < 256; gray++ )
{
sumB += prob[gray].b;
sumG += prob[gray].g;
sumR += prob[gray].r;
mTable[gray].b = (unsigned char)sumB;
mTable[gray].g = (unsigned char)sumG;
mTable[gray].r = (unsigned char)sumR;
}
}
void CWinDIPDoc::ColorMapping(BYTE *input, BYTE *output, IntRGB mTable[], CSize iSize)
{
int x, y, b, g, r, address;
for( y = 0; y < iSize.cy; y++ )
{
for( x = 0; x < iSize.cx; x++ )
{
address = BmpAddress( x, y, iSize );
b = *(input + address);
g = *(input + address + 1);
r = *(input + address + 2);
*(output + address ) = mTable[b].b;
*(output + address + 1) = mTable[g].g;
*(output + address + 2) = mTable[r].r;
}
}
}
void CWinDIPDoc::C3_4_1ImageSubtraction(int planeNum)
{
int x, y, b, g, r, tempb, tempg, tempr;
int address;
CSize iSize;
iSize.cx = width;
iSize.cy = height;
for( y = 0; y < iSize.cy; y++ )
{
for( x = 0; x < iSize.cx; x++ )
{
address = BmpAddress( x, y, iSize );
b = *( m_InputImg + address );
g = *( m_InputImg + address + 1 );
r = *( m_InputImg + address + 2 );
tempb = b;
tempg = g;
tempr = r;
b = b / planeNum * planeNum;
g = g / planeNum * planeNum;
r = r / planeNum * planeNum;
b = tempb - b;
g = tempg - g;
r = tempr - r;
*( m_InputImg + address ) = b;
*( m_InputImg + address + 1 ) = g;
*( m_InputImg + address + 2 ) = r;
}
}
C3_3_1HistogramEqualization();
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
void CWinDIPDoc::C3_6_1LowpassFiltering(int maskSize)
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
int i, **mask, maskSum;
mask = (int**)malloc( sizeof(int* ) * maskSize ); //悼利且寸 屈侥 舅酒滴扁!
for( i = 0; i < maskSize; i++ )
*(mask+i) = (int*)malloc( sizeof(int) * maskSize ); //捞巴档
LowPassMask( mask, &maskSum, maskSize );
FilteringOperation( m_InputImg, m_OutputImg, iSize, mask, maskSum, maskSize );
free(mask);
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
void CWinDIPDoc::LowPassMask(int **mask, int *maskSum, int maskSize)
{
int x, y;
for( y = 0; y < maskSize; y++ )
{
for( x = 0; x < maskSize; x++ )
mask[x][y] = 1;
}
*maskSum = maskSize * maskSize;
}
void CWinDIPDoc::FilteringOperation(BYTE *input, BYTE *output, CSize iSize, int **mask, int maskSum,
int maskSize)
{
int x, y, wHalfSize, address;
ColorRGB pixel;
wHalfSize = maskSize / 2;
for( y = wHalfSize; y < iSize.cy - wHalfSize; y++ ) //1,1俊辑何磐 矫累 荤捞令狼 付瘤阜俊辑 1猾瘤痢鳖瘤
{
for( x = wHalfSize; x < iSize.cx - wHalfSize; x++ )
{
MaskOperation( x, y, input, iSize, mask, maskSum, maskSize, &pixel ); //侨伎蔼苞 辑肺 蚌秦霖促
address = BmpAddress( x, y , iSize );
*( output + address ) = pixel.b;
*( output + address + 1 ) = pixel.g;
*( output + address + 2 ) = pixel.r;
}
}
}
void CWinDIPDoc::MaskOperation(int x, int y, BYTE *input, CSize iSize, int **mask, int maskSum,
int maskSize, ColorRGB *pixel)
{
int wx, wy, wHalfSize,address, bSum = 0, gSum = 0, rSum = 0;
int b, g, r, maskX = 0, maskY = 0;
wHalfSize = maskSize / 2;
maskSum = maskSize * maskSize;
for( wy = -wHalfSize; wy <= wHalfSize; wy++ ) //付农救俊 -1何磐 1鳖瘤 付胶农狼 农扁父怒
{
maskX = 0;
for( wx = -wHalfSize; wx <= wHalfSize; wx++ )
{
address = BmpAddress( x+wx, y+wy, iSize );
b = *( input + address );
g = *( input + address + 1 );
r = *( input + address + 2 );
bSum += mask[maskX][maskY] * b;
gSum += mask[maskX][maskY] * g;
rSum += mask[maskX][maskY] * r;
maskX++;
}
maskY++;
}
pixel->b = bSum / maskSum;
pixel->g = gSum / maskSum;
pixel->r = rSum / maskSum;
}
void CWinDIPDoc::C3_6_2Median(int maskSize)
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
int *maskArray;
maskArray = ( int* )malloc( maskSize * maskSize * sizeof( int ) ); // windowSize俊 蝶扼 皋葛府 且寸
MedianFilteringOperation( m_InputImg, m_OutputImg, iSize, maskArray, maskSize );
free( maskArray ); //皋葛府 秦力
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
void CWinDIPDoc::MedianFilteringOperation(BYTE *input, BYTE *output, CSize iSize, int *maskArray,
int maskSize)
{
int x, y, wHalfSize;
int address;
int medianValue;
int maskSum = maskSize * maskSize;
wHalfSize = maskSize / 2;
for( y = wHalfSize; y < iSize.cy - wHalfSize; y++ ){ // 抗寇贸府甫 临捞扁 困茄 康开 汲沥
for( x = wHalfSize; x < iSize.cx - wHalfSize; x++ ){
GetMaskArray( x, y, input, iSize, maskArray, maskSize ); // 付胶农 硅凯阑 掘澜
medianValue = bubbleSort( maskArray, maskSum ); // 付胶农 硅凯阑 沥纺茄 饶 吝埃 蔼阑 掘澜
address = BmpAddress( x , y , iSize ); // 付胶农 吝居狼 谅钎阑 掘绢咳
*( output + address ) = medianValue; // 付胶农 硅凯俊辑 掘绢柯 吝埃蔼阑
*( output + address + 1 ) = medianValue; // 付胶农 吝居俊 持澜
*( output + address + 2 ) = medianValue;
}
}
}
void CWinDIPDoc::GetMaskArray(int x, int y, BYTE *input, CSize iSize, int *maskArray, int maskSize)
{
int wx, wy, wHalfSize,address;
int i = 0;
wHalfSize = maskSize / 2;
for( wy = -wHalfSize; wy <= wHalfSize; wy++ ){
for( wx = -wHalfSize; wx <= wHalfSize; wx++, i++ ){
address = BmpAddress( wx + x, wy + y, iSize );
*( maskArray + i ) = *( input + address ); // 付胶农 阿 pixel蔼阑 硅凯俊 历厘
}
}
}
int CWinDIPDoc::bubbleSort(int maskArray[], int maskSum)
{
int i, j;
int temp;
for(i = 0; i < maskSum; i++){
for(j = 1; j < maskSum; j++){
if(maskArray[j-1] > maskArray[j]){
swap(&maskArray[j], &maskArray[j-1]);
}
}
}
/* for(i = maskSum - 1; i >= 0; i--){
for(j = 1; j <= i; j++){
if(maskArray[j-1] > maskArray[j]){
temp = maskArray[j-1];
maskArray[j-1] = maskArray[j];
maskArray[j] = temp;
}
}
}*/
return maskArray[maskSum / 2];
}
void CWinDIPDoc::swap(int *p, int *q)
{
int tmp;
tmp = *p;
*p = *q;
*q = tmp;
}
void CWinDIPDoc::C3_2_3Powerlaw(int m_Edit)
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
int x, y, b, g, r, address;
double gamma;
double c;
gamma = GetGammaValue(m_Edit); // 胶农费蔼栏肺 何磐 gamma蔼阑 掘绢咳.
c = 255.0 / pow(255.0, gamma); // PowerLaw拌魂侥俊辑 荤侩窍霸 瞪 拌荐 檬扁拳
for( y = 0; y < iSize.cy; y++ )
{
for( x = 0; x < iSize.cx; x++ )
{
address = BmpAddress( x, y, iSize );
b = *( m_InputImg + address );
g = *( m_InputImg + address + 1 );
r = *( m_InputImg + address + 2 );
//涝仿 康惑俊 PowerLaw甫 利侩窍咯 搬苞 蔼阑 掘澜.
*( m_OutputImg+ address ) = (BYTE)( c * pow( b , gamma ) );
*( m_OutputImg+ address + 1 ) = (BYTE)( c * pow( g , gamma ) );
*( m_OutputImg+ address + 2 ) = (BYTE)( c * pow( r , gamma ) );
}
}
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
double CWinDIPDoc::GetGammaValue(int value)
{
double gamma;
if( value == 0 ) gamma = 0.04;
else if( value == 1 ) gamma = 0.10;
else if( value == 2 ) gamma = 0.20;
else if( value == 3 ) gamma = 0.40;
else if( value == 4 ) gamma = 0.67;
else if( value == 5 ) gamma = 1.0;
else if( value == 6 ) gamma = 1.5;
else if( value == 7 ) gamma = 2.5;
else if( value == 8 ) gamma = 5.0;
else if( value == 9 ) gamma = 10.0;
else gamma = 25.0;
return gamma;
}
void CWinDIPDoc::C3_7_2Laplacian(int mask)
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
int lapMask[3][3];
LaplacianMasking( lapMask, mask );
LaplacianFilteringOperation( m_InputImg, m_OutputImg, lapMask, mask, iSize );
UpdateAllViews(FALSE); //拳搁免仿狼 盎脚.
}
void CWinDIPDoc::LaplacianMasking(int lapMask[][3], int mask)
{
int x, y;
for( y = 0; y < 3; y++ )
{
for( x = 0; x < 3; x++ )
{
if(x == 1 && y == 1)
lapMask[x][y] = 9;
else
lapMask[x][y] = -1;
}
}
}
void CWinDIPDoc::LaplacianFilteringOperation(BYTE *input, BYTE *output, int lapMask[][3], int mask, CSize iSize)
{
int x, y, wHalfSize, address;
ColorRGB pixel;
for( y = 1; y < iSize.cy - 1; y++ )
{
for( x = 1; x < iSize.cx - 1; x++ )
{
LaplacianMaskOperation(x, y, input, iSize, lapMask, mask, &pixel);
address = BmpAddress( x, y , iSize );
*( output + address ) = pixel.b;
*( output + address + 1 ) = pixel.g;
*( output + address + 2 ) = pixel.r;
}
}
}
void CWinDIPDoc::LaplacianMaskOperation(int x, int y, BYTE *input, CSize iSize, int lapMask[][3], int mask, ColorRGB *pixel)
{
int wx, wy, address, bgrSum[3] = {0, 0, 0};
int b, g, r, maskX = 0, maskY = 0, wHalfSize;
int scale = 3;
wHalfSize = 1;
for( wy = -wHalfSize; wy <= wHalfSize; wy++ ) //付农救俊 -1何磐 1鳖瘤 付胶农狼 农扁父怒
{
maskX = 0;
for( wx = -wHalfSize; wx <= wHalfSize; wx++ )
{
address = BmpAddress( x+wx, y+wy, iSize );
b = *( input + address );
g = *( input + address + 1 );
r = *( input + address + 2 );
bgrSum[0] += lapMask[maskX][maskY] * b;
bgrSum[1] += lapMask[maskX][maskY] * g;
bgrSum[2] += lapMask[maskX][maskY] * r;
maskX++;
}
maskY++;
}
if(bgrSum[0] > 255)
bgrSum[0] = 255;
if(bgrSum[1] > 255)
bgrSum[1] = 255;
if(bgrSum[2] > 255)
bgrSum[2] = 255;
if(bgrSum[0] < 0)
bgrSum[0] = 0;
if(bgrSum[1] < 0)
bgrSum[1] = 0;
if(bgrSum[2] < 0)
bgrSum[2] = 0;
pixel->b = bgrSum[0];
pixel->g = bgrSum[1];
pixel->r = bgrSum[2];
}
void CWinDIPDoc::C3_7_3Robert()
{
CSize iSize;
iSize.cx = width;
iSize.cy = height;
int scale = 2;
int x, y, address;
IntRGB pixel1 = {0, 0, 0}, pixel2 = {0, 0, 0};
int robMask1[2][2], robMask2[2][2];
RobertMasking( robMask1, 1 );
RobertMasking( robMask2, 2 );
for( y = 0; y < iSize.cy - 1; y++ ){
for( x = 0; x < iSize.cx - 1; x++ ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -