【数字图像处理】图像感兴趣区域与图像放大与缩小
生活随笔
收集整理的這篇文章主要介紹了
【数字图像处理】图像感兴趣区域与图像放大与缩小
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(一)基礎知識
圖片的放大和縮小如果不是等比例的話一定會帶來圖像的畸變。
(1)圖像的縮小
(2)圖像的放大
(3)圖像任意不成比例放大
(二)軟件設計
在這里我為了省事并沒有進行特別復雜的查只算法而是直接用之前的像素值填充。所以放大倍數超過一定限度一定會產生失真。
/*** @name: Li_Get_Roi* @msg: 獲取感興趣區域* @param {Li_Image* img 原圖像* LONG x1 左下角所在列號* LONG y1 左下角所在行號* LONG x2 右上角所在列號* LONG y2} 右上角所在行號* @return {Li_Image*}*/ LI_API Li_Image* Li_Get_Roi(Li_Image* img,LONG x1,LONG y1,LONG x2,LONG y2) {if(img==NULL||x2<x1||y2<y1||x2<0||x1<0||y2<0||y1<0) return NULL;Li_Image* out=Li_Create_Image(x2-x1,y2-y1,img->imgdepth,img->pt);for(int i=y1;i<y2;i++)for(int j=x1;j<x2;j++){BYTE* ptr1,*ptr2;ptr1=out->at(out,j-x1,i-y1);ptr2=img->at(img,j,i);memcpy(ptr1,ptr2,img->imgdepth+1);}return out; }/*** @name: Li_ReShape* @msg: 調整圖像大小* @param Li_Image* img 原圖像* LONG tag_width 圖像寬度* LONG tag_height圖像高度* @return {*}*/ LI_API Li_Image* Li_ReShape(Li_Image* img,LONG tag_width,LONG tag_height) {Li_Image* out;double dy=(double)tag_height/img->height;double dx=(double)tag_width/img->width;out=Li_Create_Image(tag_width,tag_height,img->imgdepth,img->pt);for(int i=0;i<tag_height;i++)for(int j=0;j<tag_width;j++){BYTE* ptr1,*ptr2;ptr1=out->at(out,j,i);ptr2=img->at(img,(LONG)((double)j/dx),(LONG)((double)i/dy));memcpy(ptr1,ptr2,img->imgdepth+1);}return out; }(三)應用舉例
/** @Descripttion: * @version: * @Author: Yueyang* @email: 1700695611@qq.com* @Date: 2020-10-26 19:35:49* @LastEditors: Yueyang* @LastEditTime: 2020-11-10 21:24:05*/#include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> #include "bmp.h" #include "cv.h" #include "li_image.h" #include "li_painter.h" #include "li_image_proc.h"int main() {BYTE* ptr=NULL;Li_Image* out =Li_Load_Image("./picture/whu_rgba.bmp",LI_BMP_32);Li_Image* Roi =Li_Get_Roi(out,20,20,300,300);Li_Save_Image("Roi.bmp",Roi);Li_Image* img= Li_ReShape(Roi,512,512);Li_Save_Image("shape.bmp",img);LILOG("over");return 0; }原圖:
變換后:
(四)寫在后面
因為LiteCV項目才剛剛寫了一個開頭,代碼中有錯誤的地方還望指出。我已經將項目同步到了github,我會實時更新這個代碼倉庫。
項目github地址:
LiteCV
總結
以上是生活随笔為你收集整理的【数字图像处理】图像感兴趣区域与图像放大与缩小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机器学习----多项式回归
- 下一篇: Unity学习——射箭游戏