编写函数,将图像像素从rlr2 拉伸到s1~s2。 (s2-s1)/r2-r1)=(s-s1)/r-r1) r? s=a(r-r1)+s1 其中,a=(s2-s1)/(r2-rl)
编写函数,将图像像素从r1~r2 拉伸到s1~s2。 (s2-s1)/(r2-r1) = (s-s1)/(r-r1) s = a(r-r1)+s1 其中,a = (s2-s1)/(r2-r1) r1 r2 r 0 s2 s s1
Digital Image Processing and Pattern Recognition 第四章 图像增强 线性拉伸的C/C++程序 32 void CImage:stretch(int rl,int r2, int s1,int s2,int *img_out){ //int datal]; //int row,col; 图像的高度和宽度 /从r的r1~r2变换到s的s1s2 /变换公式:(s2-s1)/(r2-r1)=(s-s1)/(r-r1) int trans[256]; 灰度变换结果 intr,s,i,j; float a=(float)(s2-s1)/(r2-r1);
Digital Image Processing and Pattern Recognition 第四章 图像增强 线性拉伸的C/C++程序 void CImage::stretch(int r1,int r2, int s1,int s2, int ** img_out){ //int data[][]; //int row, col; //图像的高度和宽度 //从r的r1~r2变换到s的s1~s2 //变换公式:(s2-s1)/(r2-r1)=(s-s1)/(r-r1) int trans[256]; //灰度变换结果 int r, s, i, j; float a=(float)(s2-s1)/(r2-r1); r1 r2 r 0 s2 s s1
Digital Image Processing and Pattern Recognition 第四章 图像增强 for (r=rl;r<=r2;r++) r1+1 r1+2 r2 sl S1+? S1+? s2 s=(int)(a*(r-r1)+s1); trans r=s; for (i=0;i<row;i++) for (j-0;j<col;j++) r-data[i]j]; img_out i]j]=trans[r];
Digital Image Processing and Pattern Recognition 第四章 图像增强 for (r=r1;r<=r2;r++) { s=(int)(a*(r-r1) + s1); trans[r] = s; } for (i=0;i<row;i++) for (j=0;j<col;j++) { r=data[i][j]; img_out[i][j]=trans[r]; } } r r1 r1+1 r1+2 . r2 s s1 S1+? S1+? . s2
s=5r-250 s=-5r+250
s =5r – 250 s =-5r +250
s=r+50 s=255-r
s =r +50 s =255-r