日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation

發布時間:2025/3/21 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實驗要求:

Zooming and Shrinking Images by Bilinear Interpolation
Objective
To manipulate another technique of zooming and shrinking images by bilinear interpolation.
Main requirements:
Ability of programming with C, C++, or Matlab.
Instruction manual:
(a) Write a computer program capable of zooming and shrinking an image by bilinear interpolation. The input to your program is the desired size of the resulting image in the horizontal and vertical direction. You may ignore aliasing effects.
(b) Download Fig. 2.19(a) and use your program to shrink this image from 1024 x 1024 to 256 x 256 pixels.
(c) Use your program to zoom the image in (b) back to 1024 x 1024. Explain the reasons for their differences.

這次實驗通過自己編寫雙線性內插法的程序來對圖像進行縮放。
簡要介紹一下雙線性內插法的原理:

第一種情況:

  • 點(i-b, j-a)與點(i-b, j+rate-a)插值得到點(1-b, j)處的灰度值;
  • 點(i+rate-b, j-a)與點(i+rate-b, j+rate-a)插值得到點(i+rate-b, j)處的灰度值;
  • 使用前面得到的結果,即點(i-b, j)與點(i+rate-b, j)進行插值得到點(i,j)處的灰度值。
  • 第二種情況:

  • 點(i-b, j-a)與點(i+rate-b, j-a)插值得到點(i, j-a)處的灰度值;
  • 點(i-b, j+rate-a)與點(i+rate-b, j+rate-a)插值得到點(i, j+rate-a)處的灰度值;
  • 使用前面得到的結果,即點(i, j-a)與點(i, j+rate-a)進行插值得到點(i,j)處的灰度值。
  • 從示意圖來看比較好理解了,詳細的資料還可以參看下面的資料鏈接:
    百度百科:雙線性插值
    雙線性插值(Bilinear Interpolation)

    代碼部分:

    matlab 函數文件名: Bilinear_Interpolation.m

    %%function img=Bilinear_Interpolation(a,rate) [m,n]=size(a); ratex=rate-1; img=zeros(m+ratex*(m-1),n+ratex*(n-1)); for i=1:m for j=1:n img(i+ratex*(i-1),j+ratex*(j-1))=a(i,j); end; end; img=double(img); for i=1:m+ratex*(m-1) for j=1:n+ratex*(n-1) a=mod(j-1,rate); b=mod(i-1,rate); if a~=0 && b==0 img(i,j)=round((a*img(i,j+(rate-a))+(rate-a)*img(i,j-a))/rate); end; if a==0 && b~=0 img(i,j)=round((b*img(i+(rate-b),j)+(rate-b)*img(i-b,j))/rate); end; if a~=0 && b~=0 img(i,j)=round((b*(a*img(i-b,j+(rate-a))+(rate-a)*img(i-b,j-a))/rate+(rate-b)*(a*img(i+(rate-b),j+(rate-a))+(rate-a)*img(i+(rate-b),j-a))/rate)/rate); end; end; end; img=uint8(img);

    程序中調用編寫好的Bilinear_Interpolation函數,查看結果:

    %%clear all;clc;close all;%%img_name = 'general_img_1024.jpg'img = imread(img_name);figure(1)imshow(img)title('原圖像');img1 = imresize(img, [256, 256]);figure(2)imshow(img1)img2 = Bilinear_Interpolation(img1, 4);figure(3)imshow(img2)title('雙線性內插法放大')%%[a, b] = size(img);n = max(a, b);c = 1024 / n;img3 = Bilinear_Interpolation(img1, c);figure(4)imshow(img3)title('雙線性內插法縮小')

    運行結果:

    《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。