下图是0.67x,0.67y的图像缩放:

机器视觉入门之路(十二,初次接触图像放大缩小,c++)

当界面想多放几张图,有时图像太大,界面窗口放不下,就会有孙大圣绣花针的想法:

void ZoomNormal(BYTE * image0,BYTE * &image1,unsigned int w,unsigned int h,
                         unsigned int & outwidth,unsigned int & outheight,double ZoomX,double ZoomY)
{
    outwidth=(int)(w*ZoomX+0.5);
    outheight=(int)(h*ZoomY+0.5);

    int newbuffersize=outwidth*outheight*4;
    image1=new BYTE[newbuffersize];
    memset(image1,255,newbuffersize);

    BYTE *copypixel=NULL;
    BYTE *objpixel=NULL;

    int x=0;
    int y=0;
    int tempY;
    int tempJ;

    for(int j=0;j<outheight;j++)
    {
        y=(int)(j/ZoomY+0.5);
        if(y>=h) y--;

        tempY=y*w*4;
        tempJ=j*outwidth*4;
        for(int i=0;i<outwidth;i++)
        {
            x=(int)(i/ZoomX+0.5);
            if(x>=w)
                x--;
            copypixel=image0+tempY+x*4;
            objpixel=image1+tempJ+i*4;
            memcpy(objpixel,copypixel,4);
        }
    }
其实除了图像的缩放,图像为了适应窗口,也是需要作出改变的,在此基础上,你能否把他改为有自适应窗口的功能呢?

这也是跟随(following)鼠标自由缩放的基础(博客中已存在),从这里,也隐含了图像尺度的概念,再如,图像金字塔的实现等等。

图像处理,要求速度高,你能否在这个算法上提高速度呢?

缩小会失去像素,放大需要插值,对于图像处理,都是比较谨慎的,因为原图像才是蓝本。

相关文章:

  • 2021-04-02
  • 2021-09-07
  • 2021-10-08
  • 2021-07-07
  • 2021-11-11
  • 2022-01-08
  • 2022-03-08
  • 2021-04-03
猜你喜欢
  • 2021-04-03
  • 2021-04-09
  • 2021-09-25
  • 2021-06-13
  • 2021-05-29
  • 2021-07-16
  • 2021-04-14
相关资源
相似解决方案