zoukankan      html  css  js  c++  java
  • 图像处理入门,一些简单的基于像素几何变换和实现

    首先是图像的缩放问题,有很多算法,不同算法缩放后的图片质量不同,目前知道的变换后图像和原图像对比的评价指标是psnr,计算公式PSNR=10*log10((2^n-1)^2/MSE);有兴趣可以去维基百科看下

    缩放的算法可以看做一种映射方式,简单的就是近邻插值了,原理是缩放后的新图像对应位置的像素值取按缩放比例映射到原图像空间的距离最近的点的像素值,比如200*100的图像,3倍放大后,新图像【100,50】位置的像素颜色为,int(100/3+0.5)=33,int(50/3+0.5)=17,取原图像【33,7】位置的颜色值,c++实现大致如下:

    定义输出图像的存储位置指针:m_ImageDataout

    输出图像宽:imagewidthout

    输出图像高:imageheightout

    原图像:m_ImageData,imagewidth,imageheight

    缩放因子:zoomx,zoomy



    imagewidthout=int(imagewidth*zoomx+0.5) ;

    imageheightout=int(imageheight*zoomy+0.5); 


    //输入图像每行像素字节数
    int lineByteIn=(imagewidth*m_nBitCount/8+3)/4*4;

    //输出图像每行像素字节数
        int lineByteOut=(imagewidthout*m_nBitCount/8+3)/4*4;


    //申请缓冲区,存放输出结果
    m_pImgDataOut=new unsigned char[lineByteOut*imageheightout];


    //每像素字节数,输入图像与输出图像相同
    int pixelByte=m_nBitCount/8;



    //输出图像在输入图像中待插值的位置坐标
    int coordinateX, coordinateY;

    //循环变量,输出图像的坐标
    int i, j;

    //循环变量,像素的每个通道
    int k;

    //近邻插值
    for(i=0; i< imageheightout; i++){
    for(j=0; j<imageheightout; j++){  
    //输出图像坐标为(j,i)的像素映射到原图中的坐标值,即插值位置
    coordinateX=j/zoomx+0.5;
    coordinateY=i/zoomy+0.5;

    //若插值位置在输入图像范围内,则近邻插值
    if(0<=coordinateX&&coordinateX<imageWidth
    && coordinateY>=0&&coordinateY<imageheight){
    for(k=0;k<pixelByte;k++)
    *(m_ImageDataout + i * lineByteOut + j*pixelByte + k) 
    =*(m_ImageData+ coordinateY*lineByteIn+ coordinateX*pixelByte + k) ;
    }
    else //若不在输入图像范围内,则置255  
    {
    for(k=0;k<pixelByte;k++)
    *(m_ImageDataout  + i * lineByteOut + j*pixelByte+k) = 255;
    }

    }
    }




    }

    matlab就很简单了,resize就可以实现newimage=imresize(image,[100 200]);其中100,200是新图像的size,默认缩放方法为nearest



  • 相关阅读:
    This counter can increment, decrement or skip ahead by an arbitrary amount
    LUT4/MUXF5/MUXF6 logic : Multiplexer 8:1
    synthesisable VHDL for a fixed ratio frequency divider
    Bucket Brigade FIFO SRL16E ( VHDL )
    srl16e fifo verilog
    DualPort Block RAM with Two Write Ports and Bytewide Write Enable in ReadFirst Mode
    Parametrilayze based on SRL16 shift register FIFO
    stm32 spi sdcard fatfs
    SPI bus master for System09 (2)
    SQLSERVER中的自旋锁
  • 原文地址:https://www.cnblogs.com/zhangdebin/p/5567963.html
Copyright © 2011-2022 走看看