Digital Image Processing Using Visual C++
Digital Image Processing Using Visual C++
• void CWinTestView::OnConstAdd()
• {
• // TODO: Add your command handler code here
• CWinTestDoc* pDoc = GetDocument();
• ASSERT_VALID(pDoc);
• for(int i=0; i<height; i++)
• {
• for(int j=0; j<width; j++)
• {
• int tempVal = pDoc->m_InImg[i][j]+60;
• tempVal = tempVal > 255 ? 255: tempVal;
• tempVal = tempVal < 0 ? 0: tempVal;
• pDoc->m_OutImg[i][j] = (unsigned char)tempVal;
• }
• }
• Invalidate(FALSE); //
• }
Contrast +
Contrast -
• void CWinTestView::OnConstSub()
• {
• // TODO: Add your command handler code here
• CWinTestDoc* pDoc = GetDocument();
• ASSERT_VALID(pDoc);
• for(int i=0; i<height; i++)
• {
• for(int j=0; j<width; j++)
• {
• int tempVal = pDoc->m_InImg[i][j]-60;
• tempVal = tempVal > 255 ? 255: tempVal;
• tempVal = tempVal < 0 ? 0: tempVal;
• pDoc->m_OutImg[i][j] = (unsigned
char)tempVal;
• }
• }
• Invalidate(FALSE);
• }
Contrast -
Histogram
Generates the Histogram Graph of Image
void CWinTestDoc::m_ImgHisto(int height, int width)
• {
• int i,j,vmax,vmin;
• for(i=0; i<256; i++) m_HistoArr[i]=0;
• ASSERT_VALID(pDoc);
• Invalidate(FALSE);
• }
Binirization
Dynamic Binirization
• void CWinTestView::OnBinDynamic()
• {
• // TODO: Add your command handler code here
• CBinCntrlDlg pbinCtrlDlg;
• pbinCtrlDlg.DoModal();
• }
Histogram Equal
• void CWinTestView::OnHistoEqual()
• {
• // TODO: Add your command handler code here
• CWinTestDoc* pDoc = GetDocument();
• ASSERT_VALID(pDoc);
• pDoc->m_HistoEqual(256,256);
• Invalidate(FALSE);
• }
Histogram Equal
Histogram Stretch
• void CWinTestView::OnHistoStretch()
• {
• // TODO: Add your command handler code here
• CWinTestDoc* pDoc = GetDocument();
• ASSERT_VALID(pDoc);
• pDoc->m_HistoStretch(256,256);
• Invalidate(FALSE);
• }
Histogram UpStretch
• void CWinTestView::OnHistoUpstretch()
• {
• // TODO: Add your command handler code here
• CWinTestDoc* pDoc = GetDocument();
• ASSERT_VALID(pDoc);
• pDoc->m_HistoUpStretch(256,256,20,20);
• Invalidate(FALSE);
• }
Chapter 7
• Main Review
– Functions Applied in this chapter on Images
are
• Smoothing Box
• Smoothing (Gaussian)
• Sharpening (Laplacian)
• Edge (Prewitt)
• Edge (Sobel)
Smoothing Box
• void CWinTestDoc::m_SmoothingBox(int height, int width)
• {
• int MaskBox[3][3]={{1,1,1}, {1,1,1}, {1,1,1}};
• int heightm1=height-1;
• int widthm1=width-1;
• int mr,mc;
• int newValue;
• int i,j;
• for(i=0;i<height;i++)
• for(j=0;j<width;j++)
• m_OutImg[i][j]=0;
• for(i=1; i<heightm1; i++)
• {
• for(j=1; j<widthm1; j++)
• {
• newValue=0; -
• for(mr=0;mr<3;mr++)
• for(mc=0;mc<3;mc++)
• newValue += (MaskBox[mr][mc]*m_InImg[i+mr-1][j+mc-1]);
• newValue /= 9;
• m_OutImg[i][j]=(BYTE)newValue;
• }
• }
• }
Smoothing Box
Smoothing (Gaussian)
• void CWinTestDoc::m_SmoothingGaussian(int height, int width)
• {
• int MaskGaussian[3][3]={{1,2,1}, {2,4,2}, {1,2,1}};
• int heightm1=height-1;
• int widthm1=width-1;
• int mr,mc;
• int newValue;
• int i,j;
• for(i=0;i<height;i++)
• for(j=0;j<width;j++)
• m_OutImg[i][j]=0;
• for(i=1; i<heightm1; i++)
• {
• for(j=1; j<widthm1; j++)
• {
• newValue=0;
• for(mr=0;mr<3;mr++)
• for(mc=0;mc<3;mc++)
• newValue += (MaskGaussian[mr][mc]*m_InImg[i+mr-1][j+mc-1]);
• newValue /= 20;
• m_OutImg[i][j]=(BYTE)newValue;
• }
• }
• }
Smoothing (Gaussian)
Sharpening (Laplacian)
• void CWinTestDoc::m_SharpeningLaplacian(int height, int width)
• {
• int MaskBox[3][3]={{-1,-1,-1}, {-1,8,-1}, {-1,-1,-1}};
• int heightm1=height-1;
• int widthm1=width-1;
• int mr,mc;
• int newValue;
• int i,j;
• int *pTmpImg;
• int min,max;
• float constVal1,constVal2;
• pTmpImg=new int[height*width];
• for(i=0;i<height;i++)
• for(j=0;j<width;j++)
• {
• m_OutImg[i][j]=0;
• pTmpImg[i*width+j]=0;
• }