【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-IProcessD.cpp,希望本篇文章对您学习有所帮助。
// IProcessD.cpp
#include "stdafx.h"
#ifndef _INC_IPROCESSDC
#define _INC_IPROCESSDC
int nDirectionNo=0;
void GrayScaleTransfor(CImage *pImgm,int n)
{
struct IMAGEPARAMENT P;
BYTE **list;
long pg[256],tab[256];
RGBQUAD ColorTab[256];
int i,T_gray[256];
GetImageParament(pImgm,&P);
Histogram(pImgm,0,0,P.nWidth,P.nHeight,pg);
switch(n) {
case 1:
GT_linear(T_gray);
break;
case 2:
GT_sqrt(T_gray);
break;
case 3:
GT_log(T_gray);
break;
case 4:
GT_square(T_gray);
break;
case 5:
GT_exp(T_gray);
break;
case 6:
GT_Equal(pg,T_gray);
break;
case 7:
for (i=0;i<256;i++) tab[i]=i;
GT_histo_eq(pg,tab,T_gray);
break;
case 8:
GT_nega(T_gray);
break;
case 9:
Border_Equal(pg,T_gray);
break;
case 10:
DensitySegment(ColorTab);
SetAllPalette(pImgm,ColorTab);
break;
case 11:
PsendoColor(ColorTab);
SetAllPalette(pImgm,ColorTab);
break;
}
if (n<10) {
list=(BYTE**) Create2DList(pImgm);
GT(list,P.nWidth,P.nHeight,T_gray);
Release2DList(list);
}
}
void Threshold(CImage *pImgm,int n,double ff)
{
struct IMAGEPARAMENT P;
BYTE **list,*lpBuf;
RGBQUAD ColorTab[256];
long pg[256];
int t,x,y,thre;
int tab[256],buf[20],bn;
GetImageParament(pImgm,&P);
list=(BYTE**) Create2DList(pImgm);
histog(list,pg,0,0,P.nWidth,P.nHeight);
switch(n) {
case 1:
thre=FormAnalysis(pg,tab,buf,&bn);
break;
case 2:
t=GrayImageType(pg);
if (t==1) ff=1.0-ff;
thre=Ptile(pg,ff);
break;
case 3:
thre=Otsu(pg);
break;
case 4:
thre=Minimum(pg);
break;
case 5:
thre=KSW_Entropic(pg);
break;
case 6:
thre=BiasNormal(pg);
break;
case 7:
thre=Moment(pg);
break;
case 8:
thre=ColligationThreshold(pg);
break;
case 9:
thre=SimpleThreshold(pg);
break;
}
for (y=0;y<P.nHeight;y++) {
lpBuf=(BYTE*) pImgm->GetPixelAddress(0,y);
for (x=0;x<P.nWidth;x++,lpBuf++) {
if (*lpBuf>=thre) *lpBuf=1;
else *lpBuf=0;
}
}
memset(ColorTab,0,1024);
SetAllPalette(pImgm,ColorTab);
SetPalette(pImgm,1,255,255,255);
Release2DList(list);
}
void ExpandImage(CImage *pImgn,CImage *pImgm)
{
struct IMAGEPARAMENT P;
BYTE *buf,*buf1;
int k;
GetImageParament(pImgm,&P);
pImgn->Create(P.nWidth+2,P.nHeight+2,P.nBitCount,0);
for (int i=0;i<P.nHeight;i++) {
buf = (BYTE*) pImgm->GetPixelAddress(0,i);
buf1 = (BYTE*) pImgn->GetPixelAddress(1,i+1);
memcpy(buf1, buf, P.nBytesPerLine);
}
buf = (BYTE*) pImgm->GetPixelAddress(0,0);
buf1 = (BYTE*) pImgn->GetPixelAddress(1,0);
memcpy(buf1, buf, P.nBytesPerLine);
buf = (BYTE*) pImgm->GetPixelAddress(0,P.nHeight-1);
buf1 = (BYTE*) pImgn->GetPixelAddress(1,P.nHeight+1);
memcpy(buf1, buf, P.nBytesPerLine);
buf=(BYTE*) malloc(P.nHeight);
GetRectValue(pImgm,0,0,1,P.nHeight,buf);
SetRectValue(pImgn,0,1,1,P.nHeight,buf);
GetRectValue(pImgm,P.nWidth-1,0,1,P.nHeight,buf);
SetRectValue(pImgn,P.nWidth+1,1,1,P.nHeight,buf);
k=GetPixelValue(pImgm,0,0);
SetPixelValue(pImgn,0,0,k);
k=GetPixelValue(pImgm,P.nWidth-1,0);
SetPixelValue(pImgn,P.nWidth+1,0,k);
k=GetPixelValue(pImgm,0,P.nHeight-1);
SetPixelValue(pImgn,0,P.nHeight+1,k);
k=GetPixelValue(pImgm,P.nWidth-1,P.nHeight-1);
SetPixelValue(pImgn,P.nWidth+1,P.nHeight+1,k);
free(buf);
}
void ReduceImage(CImage *pImgn,CImage *pImgm)
{
struct IMAGEPARAMENT P;
BYTE *buf,*buf0;
GetImageParament(pImgn,&P);
for (int i=0;i<P.nHeight;i++) {
buf0 = (BYTE*) pImgm->GetPixelAddress(1,i+1);
buf = (BYTE*) pImgn->GetPixelAddress(0,i);
memcpy(buf, buf0, P.nBytesPerLine);
}
}
void LocalProcess(CImage *pImg,int n)
{
struct IMAGEPARAMENT P;
BYTE **list1,**list0;
RGBQUAD ColorTab[256];
CImage gImg1,gImg0;
ExpandImage(&gImg1,pImg);
GetImageParament(&gImg1,&P);
gImg0.Create(P.nWidth,P.nHeight,P.nBitCount,0);
ImageCopy(&gImg0,&gImg1);
list1=(BYTE**) Create2DList(&gImg1);
list0=(BYTE**) Create2DList(&gImg0);
GetImageParament(&gImg1,&P);
switch(n) {
case 1:
Gradiant(list0,list1,P.nWidth,P.nHeight);
break;
case 2:
Roberts(list0,list1,P.nWidth,P.nHeight);
break;
case 3:
Sobel(list0,list1,P.nWidth,P.nHeight);
break;
case 4:
Laplacian(list0,list1,P.nWidth,P.nHeight);
break;
case 5:
Kirsch(list0,list1,P.nWidth,P.nHeight,nDirectionNo);
break;
case 6:
Robinson(list0,list1,P.nWidth,P.nHeight,nDirectionNo);
break;
case 7:
Prewitt(list0,list1,P.nWidth,P.nHeight,nDirectionNo);
break;
case 8:
Smooth5(list0,list1,P.nWidth,P.nHeight);
break;
case 9:
Smooth9(list0,list1,P.nWidth,P.nHeight);
break;
case 10:
Median5(list0,list1,P.nWidth,P.nHeight);
break;
case 11:
Median9(list0,list1,P.nWidth,P.nHeight);
break;
case 12:
BoundEnhance(list0,list1,P.nWidth,P.nHeight);
break;
case 13:
LapSketch(list0,list1,P.nWidth,P.nHeight);
break;
case 14:
LoG(list0,list1,P.nWidth,P.nHeight);
break;
case 15:
OnePWidthW(list0,list1,P.nWidth,P.nHeight);
break;
case 16:
RemoveLineNoise(list0,list1,P.nWidth,P.nHeight);
break;
case 17:
SobelThin(list0,list1,P.nWidth,P.nHeight);
break;
case 18:
LogPrewitt(list0,list1,P.nWidth,P.nHeight,0.5);
break;
}
Release2DList(list1);
Release2DList(list0);
ReduceImage(pImg,&gImg0);
if (n==18) {
memset(ColorTab,0,1024);
SetAllPalette(pImg,ColorTab);
SetPalette(pImg,1,255,255,255);
}
gImg1.Destroy();
gImg0.Destroy();
}
void CurveThinning(CImage *pImg0,CImage *pImg1,int n)
{
struct IMAGEPARAMENT P;
BYTE **list;
LowTypeToIndex(pImg0,pImg1);
SetPalette(pImg0,0,0,0,0);
SetPalette(pImg0,1,255,255,255);
GetImageParament(pImg0,&P);
list=(BYTE**) Create2DList(pImg0);
switch(n) {
case 1:
Hilditch(list,P.nBytesPerLine,P.nHeight);
break;
case 2:
Deutch(list,P.nBytesPerLine,P.nHeight);
break;
case 3:
FastThin(list,P.nBytesPerLine,P.nHeight);
break;
case 4:
Naccache(list,P.nBytesPerLine,P.nHeight);
break;
case 5:
Pavlidis1(list,P.nBytesPerLine,P.nHeight);
break;
case 6:
Pavlidis2(list,P.nBytesPerLine,P.nHeight);
break;
case 7:
Rosenfeld4(list,P.nBytesPerLine,P.nHeight);
break;
case 8:
Rosenfeld8(list,P.nBytesPerLine,P.nHei
上一篇:
frm_jcsj_lbxx.frm
下一篇:
临床前药物安全性评价中毒性病理学新技术的应用