📄 rsimage.cpp
字号:
SearchX = (float)j*m_nImgWidth/nResWidth;
if(nType == 0)
{
ISearchX = (int)SearchX;
ISearchY = (int)SearchY;
if(m_nImgType == IMAGE_COMBINE)
{
m_pImgData[(nResHeight-i)*ResBmpCol+3*(j-1)] = m_pUndoData[(m_nImgHeight-ISearchY)*BmpCol+3*(ISearchX-1)];
m_pImgData[(nResHeight-i)*ResBmpCol+3*(j-1)+1] = m_pUndoData[(m_nImgHeight-ISearchY)*BmpCol+3*(ISearchX-1)+1];
m_pImgData[(nResHeight-i)*ResBmpCol+3*(j-1)+2] = m_pUndoData[(m_nImgHeight-ISearchY)*BmpCol+3*(ISearchX-1)+2];
}
else
m_pImgData[(nResHeight-i)*ResBmpCol+j-1] = m_pUndoData[(m_nImgHeight-ISearchY)*BmpCol+(ISearchX-1)];
}
else if(nType == 1)
{
ISearchX = (int)SearchX;
ISearchY = (int)SearchY;
XShift = SearchX-ISearchX;
YShift = SearchY-ISearchY;
for(int k=0; k<Times; k++)
{
tempX = SymFold(ISearchX,m_nImgWidth);
tempY = SymFold(ISearchY,m_nImgHeight);
Byte[0][0] = m_pUndoData[(m_nImgHeight-tempY-1)*BmpCol+tempX*Times+k];
tempX = SymFold(ISearchX+1,m_nImgWidth);
tempY = SymFold(ISearchY,m_nImgHeight);
Byte[0][1] = m_pUndoData[(m_nImgHeight-tempY-1)*BmpCol+tempX*Times+k];
tempX = SymFold(ISearchX,m_nImgWidth);
tempY = SymFold(ISearchY+1,m_nImgHeight);
Byte[0][2] = m_pUndoData[(m_nImgHeight-tempY-1)*BmpCol+tempX*Times+k];
tempX = SymFold(ISearchX+1,m_nImgWidth);
tempY = SymFold(ISearchY+1,m_nImgHeight);
Byte[0][2] = m_pUndoData[(m_nImgHeight-tempY-1)*BmpCol+tempX*Times+k];
Res[0] = (float)Byte[0][0]+(float)(Byte[0][1]-Byte[0][0])*XShift;
Res[1] = (float)Byte[0][2]+(float)(Byte[0][3]-Byte[0][2])*XShift;
m_pImgData[(nResHeight-i)*ResBmpCol+(j-1)*Times+k] = (BYTE)(Res[0]+(Res[1]-Res[0])*YShift);
}
}
else
{
ISearchX = (int)SearchX; //行方向
ISearchY = (int)SearchY; //列方向
XShift = SearchX-ISearchX; //行方向
YShift = SearchY-ISearchY; //列方向
for(int k=0; k<Times; k++)
{
// 取值
for(int m=0; m<4; m++)
{
tempX = SymFold(ISearchX-1+m,m_nImgWidth);
for(int n=0; n<4; n++)
{
tempY = SymFold(n+ISearchY-1,m_nImgHeight);
Byte[m][n] = m_pUndoData[(m_nImgHeight-tempY-1)*BmpCol+tempX*Times+k];
}
}
// 先进行行变换
for(m=0; m<4; m++)
{
Res[m] = - XShift*(1-XShift)*(1-XShift)*Byte[0][m]
+ (1-XShift*XShift*(2-XShift))*Byte[1][m] +
XShift*(1+XShift-XShift*XShift)*Byte[2][m]
- XShift*XShift*(1-XShift)*Byte[3][m];
}
// 再进行列变换
tempRes = - YShift*(1-YShift)*(1-YShift)*Res[0]
+ (1-YShift*YShift*(2-YShift))*Res[1] +
YShift*(1+YShift-YShift*YShift)*Res[2]
- YShift*YShift*(1-YShift)*Res[3];
if(tempRes>255.0) tempRes = 255.0;
if(tempRes<0.0)tempRes = 0.0;
m_pImgData[(nResHeight-i)*ResBmpCol+(j-1)*Times+k] = (BYTE)tempRes;
}
}
}
}
m_nImgWidth = nResWidth;
m_nImgHeight = nResHeight;
}
// 锐化遥感影象
void CRSImage::Sharpen()
{
int Times;
if(m_nImgType == IMAGE_COMBINE)
Times = 3;
else
Times = 1;
int BmpCol = (m_nImgWidth*Times+3)/4*4;
if(m_pUndoData != NULL)
{
delete []m_pUndoData;
}
m_pUndoData = m_pImgData;
m_pImgData = NULL;
m_pImgData = (LPBYTE)new BYTE[BmpCol*m_nImgHeight];
if(m_pImgData == NULL)
{
AfxMessageBox("没有足够内存完成操作!");
return;
}
int *pLine = new int[BmpCol];
int RPro;
int Process = 0;
DWORD dwOrder;
//int nRes;
for(int i=0; i<m_nImgHeight; i++)
{
RPro=(int)(100.0 * (i+1) / m_nImgHeight);
if(RPro>Process)
{
for(int j=0;j<RPro-Process;j++)
UpdateStatusBar();
Process=RPro;
}
if(i==0 || i==m_nImgHeight-1)
for(int j=0; j<BmpCol; j++)
{
pLine[j] = 0;
}
else
{
for(int j=0; j<m_nImgWidth; j++)
{
for(int k=0; k<Times; k++)
{
if(j==0 || j==Times)
pLine[Times*j+k] = 0;
else
{
dwOrder = (m_nImgHeight-i-1)*BmpCol+Times*j+k;
pLine[Times*j+k] = (int)(m_pUndoData[dwOrder])*4-
m_pUndoData[dwOrder+Times]-
m_pUndoData[dwOrder-Times]-
m_pUndoData[dwOrder+BmpCol]-
m_pUndoData[dwOrder-BmpCol];
}
}
}
}
for(int j=0; j<BmpCol; j++)
{
int nRes = (int)(m_pUndoData[(m_nImgHeight-i-1)*BmpCol+j])+pLine[j];
if(nRes<0)
m_pImgData[(m_nImgHeight-i-1)*BmpCol+j] = 0;
else if(nRes>255)
m_pImgData[(m_nImgHeight-i-1)*BmpCol+j] = 255;
else
m_pImgData[(m_nImgHeight-i-1)*BmpCol+j] = (BYTE)nRes;
}
}
delete []pLine;
}
// 影象旋转
void CRSImage::Rotate(double Degree,bool flag)
{
int Times;
if(m_nImgType == IMAGE_COMBINE)
Times = 3;
else
Times = 1;
int BmpCol = (m_nImgWidth*Times+3)/4*4;
int ResWidth;
int ResHeight;
float Thita;
if(Degree > 180.0)
Degree = 360.0-Degree;
if(Degree >=0 && Degree<=90)
{
Thita = float(Degree*PI/180);
ResWidth = int(m_nImgWidth*cos(Thita)+m_nImgHeight*sin(Thita));
ResHeight = int(m_nImgWidth*sin(Thita)+m_nImgHeight*cos(Thita));
}
else if(Degree>90 && Degree<=180)
{
Thita = float((Degree-90)*PI/180);
ResHeight = int(m_nImgWidth*cos(Thita)+m_nImgHeight*sin(Thita));
ResWidth = int(m_nImgWidth*sin(Thita)+m_nImgHeight*cos(Thita));
}
int ResBmpCol = (ResWidth*Times+3)/4*4;
if(m_pUndoData != NULL)
delete []m_pUndoData;
m_pUndoData = m_pImgData;
m_pImgData = (BYTE *)new BYTE[ResHeight*ResBmpCol];
ASSERT(m_pImgData != NULL);
int RPro;
int Process = 0;
double Sin;
double Cos;
int TheY2;
int NewX;
int NewY;
if(Degree>=0 && Degree<=90)
{
Sin = sin(Thita);
Cos = cos(Thita);
for(int i=0; i<ResHeight; i++)
{
RPro=(int)(100.0 * (i+1) / ResHeight);
if(RPro>Process)
{
for(int j=0; j<RPro-Process; j++)
UpdateStatusBar();
Process=RPro;
}
if(flag)
TheY2 = ResHeight-1-i;
else
TheY2 = i;
for(int j=0; j<ResWidth; j++)
{
NewX = (int)(m_nImgWidth*Sin*Sin-(i*Sin-j*Cos)+0.5);
NewY = (int)(-m_nImgWidth*Sin*Cos+(i*Cos+j*Sin)+0.5);
for(int k=0; k<Times; k++)
{
if(flag)
{
if(NewX<0||NewX>(m_nImgWidth-1)||NewY<0||NewY>(m_nImgHeight-1))
m_pImgData[(DWORD)TheY2*ResBmpCol+j*Times+k] = 0;
else
m_pImgData[(DWORD)TheY2*ResBmpCol+j*Times+k] = m_pUndoData[(m_nImgHeight-NewY-1)*BmpCol+NewX*Times+k];
}
else
{
if(NewX<0||NewX>(m_nImgWidth-1)||NewY<0||NewY>(m_nImgHeight-1))
m_pImgData[(DWORD)TheY2*ResBmpCol+j*Times+k] = 0;
else
m_pImgData[(DWORD)TheY2*ResBmpCol+j*Times+k] = m_pUndoData[NewY*BmpCol+NewX*Times+k];
}
}
}
}
}
else if(Degree>90 && Degree<=180)
{
Sin = sin(Thita);
Cos = cos(Thita);
for(int i=0; i<ResHeight; i++)
{
RPro=(int)(100.0 * (i+1) / ResHeight);
if(RPro>Process)
{
for(int j=0; j<RPro-Process; j++)
UpdateStatusBar();
Process=RPro;
}
if(flag)
TheY2 = ResHeight-1-i;
else
TheY2 = i;
for(int j=0; j<ResWidth; j++)
{
NewY = m_nImgHeight-(int)(i*Sin-(j-m_nImgHeight*Cos)*Cos);
NewX = m_nImgWidth-(int)((i-m_nImgHeight*Sin)*Cos+j*Sin);
for(int k=0;k<Times;k++)
{
if(flag)
{
if(NewX<0||NewX>(m_nImgWidth-1)||NewY<0||NewY>(m_nImgHeight-1))
m_pImgData[(DWORD)TheY2*ResBmpCol+j*Times+k] = 0;
else
{
m_pImgData[TheY2*ResBmpCol+j*Times+k] =
m_pUndoData[(m_nImgHeight-NewY-1)*BmpCol+NewX*Times+k];
}
}
else
{
if(NewX<0||NewX>(m_nImgWidth-1)||NewY<0||NewY>(m_nImgHeight-1))
m_pImgData[(DWORD)TheY2*ResBmpCol+j*Times+k] = 0;
else
{
m_pImgData[TheY2*ResBmpCol+j*Times+k] =
m_pUndoData[NewY*BmpCol+NewX*Times+k];
}
}
}
}
}
}
m_nImgHeight = ResHeight;
m_nImgWidth = ResWidth;
}
// 图象颜色反转
void CRSImage::Revert()
{
if(m_nImgType == IMAGE_THEMATIC)
{
AfxMessageBox("专题影象做颜色反转无多大意义!");
return;
}
int nBmpCol;
if(m_nImgType == IMAGE_SINGLEBAND)
nBmpCol = (m_nImgWidth+3)/4*4;
else
nBmpCol = (m_nImgWidth*3+3)/4*4;
int RPro;
int Process = 0;
for(int i=0; i<m_nImgHeight; i++)
{
RPro=(int)(100.0*(i+1)/m_nImgHeight);
if(RPro>Process)
{
for(int j=0;j<RPro-Process;j++)
UpdateStatusBar();
Process=RPro;
}
for(int j=0; j<m_nImgWidth; j++)
{
if(m_nImgType != IMAGE_COMBINE)
*(m_pImgData+(DWORD)i*nBmpCol+j) = 255-*(m_pImgData+(DWORD)i*nBmpCol+j);
else /*if(m_nImgType == IMAGE_COMBINE)*/
{
*(m_pImgData+(DWORD)i*nBmpCol+3*j) = 255-*(m_pImgData+(DWORD)i*nBmpCol+3*j);
*(m_pImgData+(DWORD)i*nBmpCol+3*j+1) = 255-*(m_pImgData+(DWORD)i*nBmpCol+3*j+1);
*(m_pImgData+(DWORD)i*nBmpCol+3*j+2) = 255-*(m_pImgData+(DWORD)i*nBmpCol+3*j+2);
}
}
}
if(m_pdwHistogram != NULL)
{
DWORD TempDW;
if(m_nImgType != IMAGE_COMBINE)
{
for(int i=0; i<128; i++)
{
TempDW = m_pdwHistogram[i];
m_pdwHistogram[i] = m_pdwHistogram[256-i-1];
m_pdwHistogram[256-i-1] = TempDW;
}
}
else
{
for(int i=0; i<128; i++)
{
TempDW = m_pdwHistogram[i];
m_pdwHistogram[i] = m_pdwHistogram[256-i-1];
m_pdwHistogram[256-i-1] = TempDW;
TempDW = m_pdwHistogram[256+i];
m_pdwHistogram[256+i] = m_pdwHistogram[256+256-i-1];
m_pdwHistogram[256+256-i-1] = TempDW;
TempDW = m_pdwHistogram[2*256+i];
m_pdwHistogram[2*256+i] = m_pdwHistogram[2*256+256-i-1];
m_pdwHistogram[2*256+256-i-1] = TempDW;
}
}
}
}
// 获取某块区域的图象数据
BOOL CRSImage::GetDataBlock(LPBYTE &pData,RECT &rectToGet)
{
if(pData != NULL)
{
delete []pData;
pData = NULL;
}
if(pData == NULL)
{
if(m_nImgType == IMAGE_COMBINE)
{
pData = (BYTE *)new BYTE[(rectToGet.right-rectToGet.left+1)*
(rectToGet.bottom-rectToGet.top+1)*3];
}
else
{
pData = (BYTE *)new BYTE[(rectToGet.right-rectToGet.left+1)*
(rectToGet.bottom-rectToGet.top+1)];
}
if(pData == NULL)
{
AfxMessageBox("申请内存失败!");
return FALSE;
}
}
int nBmpCol;
int nLineWidth;
if(m_nImgType != IMAGE_COMBINE)
{
nBmpCol = (m_nImgWidth+3)/4*4;
nLineWidth = rectToGet.right-rectToGet.left+1;
}
else
{
nBmpCol = (m_nImgWidth*3+3)/4*4;
nLineWidth = (rectToGet.right-rectToGet.left+1)*3;
}
for(int i=rectToGet.top; i<=rectToGet.bottom; i++)
{
for(int j=rectToGet.left; j<=rectToGet.right; j++)
{
if(m_nImgType != IMAGE_COMBINE)
pData[(i-rectToGet.top)*nLineWidth+j-rectToGet.left] =
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j];
else
{
pData[(i-rectToGet.top)*nLineWidth+(j-rectToGet.left)*3] =
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j*3];
pData[(i-rectToGet.top)*nLineWidth+(j-rectToGet.left)*3+1] =
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j*3+1];
pData[(i-rectToGet.top)*nLineWidth+(j-rectToGet.left)*3+2] =
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j*3+2];
}
}
}
return TRUE;
}
// 重写某块数据
BOOL CRSImage::SetDataBlock(LPBYTE pData,RECT & rectToSet)
{
int nBmpCol;
int nLineWidth;
if(m_nImgType != IMAGE_COMBINE)
{
nBmpCol = (m_nImgWidth+3)/4*4;
nLineWidth = rectToSet.right-rectToSet.left+1;
}
else
{
nBmpCol = (m_nImgWidth*3+3)/4*4;
nLineWidth = (rectToSet.right-rectToSet.left+1)*3;
}
for(int i=rectToSet.top; i<=rectToSet.bottom; i++)
{
for(int j=rectToSet.left; j<=rectToSet.right; j++)
{
if(m_nImgType != IMAGE_COMBINE)
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j] = pData[(i-rectToSet.top)*nLineWidth+j-rectToSet.left];
else
{
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j*3] = pData[(i-rectToSet.top)*nLineWidth+(j-rectToSet.left)*3];
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j*3+1] = pData[(i-rectToSet.top)*nLineWidth+(j-rectToSet.left)*3+1];
m_pImgData[(m_nImgHeight-i-1)*nBmpCol+j*3+2] = pData[(i-rectToSet.top)*nLineWidth+(j-rectToSet.left)*3+2];
}
}
}
return TRUE;
}
/*
// 获取遥感影象的名字
void CRSImage::GetImageName(LPCTSTR szImageFileName,CString & szImageName)
{
char szInfFileName[256];
char szFileName[256];
char drive[3];
char dir[256];
char ext[5];
CFile file;
// 获得对应的遥感影象的头文件的名字
_splitpath( szImageFileName, drive, dir, szFileName, ext );
strcpy( szInfFileName , drive );
strcat( szInfFileName , dir);
strcat( szInfFileName , szFileName);
strcat( szInfFileName , ".inf");
// 获取影象的名字
if(0 == file.Open(szInfFileName,CFile::modeRead))
{
szImageName.Empty();
return;
}
CRSImage *pRsImage = new CRSImage();
if(!pRsImage->LoadRsInfo(&file))
{
szImageName.Empty();
}
else
{
szImageName = pRsImage->m_szImgName;
}
file.Close();
delete pRsImage;
}
*/
// 画遥感影象
void CRSImage::Draw(CDC * pDC, int nBeginX=0, int nBeginY=0, double dRatio=1.0)
{
if(m_nImgType==IMAGE_COMBINE)
ShowRGBRsMap(pDC,nBeginX,nBeginY,dRatio);
else
ShowRsMap(pDC,nBeginX,nBeginY,dRatio);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -