snifer

赛 基于ADI的Blackfin ADSP-BF592的电子显微镜系统-图像放大实现(原创)

0
阅读(3246)

周末在实验室加班到2点,大家都很困,可怜的孩子们哪,期间除了好几个错,调试啊,修改啊,查资料啊,终于成功了,非常有成就感,基于ADI的Blackfin ADSP-BF592的电子显微镜系统-图像放大实现,整个系统实现的难点被我们攻克!!!

#include "highgui.h" //Includes
#pragma comment(lib,"highgui.lib") //Link to .lib
#pragma comment(lib,"cxcore.lib") //Link to .lib
int main()
{
IplImage *img; //Original image
IplImage *img_s; //Scaled image
int i,j;
double xs=6,ys=6;
img=cvLoadImage("cell.bmp",-1); //Load the original image
img_s=cvCreateImage(cvSize((int)img->width*xs,(int)img->height*ys),img->depth,img->nChannels);//Apply memory for scaled image

double xm,ym;
unsigned char vff0,vff1,vff2,vcf0,vcf1,vcf2,vfc0,vfc1,vfc2,vcc0,vcc1,vcc2;
unsigned char v0,v1,v2;
for(i=0;iheight;i++){
for(j=0;jwidth;j++){
//Middle pixel中间像素
xm=(img->width-1)*j/(double)img_s->width;
ym=(img->height-1)*i/(double)img_s->height;
//4 neighbor pixels of 3 color
vff0=img->imageData[((int)floor(ym))*img->widthStep+((int)floor(xm))*img->nChannels+0];
vff1=img->imageData[((int)floor(ym))*img->widthStep+((int)floor(xm))*img->nChannels+1];
vff2=img->imageData[((int)floor(ym))*img->widthStep+((int)floor(xm))*img->nChannels+2];
vcf0=img->imageData[((int)floor(ym))*img->widthStep+((int)ceil(xm))*img->nChannels+0];
vcf1=img->imageData[((int)floor(ym))*img->widthStep+((int)ceil(xm))*img->nChannels+1];
vcf2=img->imageData[((int)floor(ym))*img->widthStep+((int)ceil(xm))*img->nChannels+2];
vfc0=img->imageData[((int)ceil(ym))*img->widthStep+((int)floor(xm))*img->nChannels+0];
vfc1=img->imageData[((int)ceil(ym))*img->widthStep+((int)floor(xm))*img->nChannels+1];
vfc2=img->imageData[((int)ceil(ym))*img->widthStep+((int)floor(xm))*img->nChannels+2];
vcc0=img->imageData[((int)ceil(ym))*img->widthStep+((int)ceil(xm))*img->nChannels+0];
vcc1=img->imageData[((int)ceil(ym))*img->widthStep+((int)ceil(xm))*img->nChannels+1];
vcc2=img->imageData[((int)ceil(ym))*img->widthStep+((int)ceil(xm))*img->nChannels+2];
//Perform linear interpolation执行内插
v0=vff0+(vcf0-vff0)*(xm-(int)xm)+(vfc0+(vcc0-vfc0)*(xm-(int)xm)-vff0-(vcf0-vff0)*(xm-(int)xm))*(ym-(int)ym);
v1=vff1+(vcf1-vff1)*(xm-(int)xm)+(vfc1+(vcc1-vfc1)*(xm-(int)xm)-vff1-(vcf1-vff1)*(xm-(int)xm))*(ym-(int)ym);
v2=vff2+(vcf2-vff2)*(xm-(int)xm)+(vfc2+(vcc2-vfc2)*(xm-(int)xm)-vff2-(vcf2-vff2)*(xm-(int)xm))*(ym-(int)ym);
//Set pixel of scaled image
img_s->imageData[i*img_s->widthStep+j*img_s->nChannels+0]=v0;
img_s->imageData[i*img_s->widthStep+j*img_s->nChannels+1]=v1;
img_s->imageData[i*img_s->widthStep+j*img_s->nChannels+2]=v2;
}
}
cvSaveImage("img.jpg",img_s);
cvNamedWindow("Scaled image",CV_WINDOW_AUTOSIZE);
cvShowImage("Scaled image",img_s);
cvWaitKey(1000000);
cvReleaseImage(&img);
cvReleaseImage(&img_s);
return 0;
}

呵呵,具体的原理可在本系统的第一次介绍中有,感兴趣的朋友可以提点意见!!!

Baidu
map