亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

雙線(xiàn)性插值理解與Python實(shí)現(xiàn)

系統(tǒng) 2332 0

轉(zhuǎn)載自https://blog.csdn.net/sinat_37011812/article/details/81842957
雙線(xiàn)性插值
雙線(xiàn)性插值理解與Python實(shí)現(xiàn)_第1張圖片
雙線(xiàn)性插值理解與Python實(shí)現(xiàn)_第2張圖片
公式就是這么推來(lái)的,主要就是在x方向和y方向上都進(jìn)行線(xiàn)性插值,利用臨近點(diǎn)進(jìn)行計(jì)算

在計(jì)算的時(shí)候利用了幾何中心對(duì)齊來(lái)優(yōu)化原來(lái)的直接縮放

            
              __author__ = 'Alex Wang'
 
import numpy as np
import cv2
import time
 
 
'''
python implementation of bilinear interpolation
'''
 
 
def bilinear_interpolation(img,out_dim):
    src_h, src_w, channel = img.shape
    dst_h, dst_w = out_dim[1], out_dim[0]
    if src_h == dst_h and src_w == dst_w:
        return img.copy()
    dst_img = np.zeros((dst_h,dst_w,3),dtype=np.uint8)
    scale_x, scale_y = float(src_w) / dst_w, float(src_h) / dst_h
    for i in range(3):
        for dst_y in range(dst_h):
            for dst_x in range(dst_w):
 
                # find the origin x and y coordinates of dst image x and y
                # use geometric center symmetry
                # if use direct way, src_x = dst_x * scale_x
                src_x = (dst_x + 0.5) * scale_x - 0.5
                src_y = (dst_y + 0.5) * scale_y - 0.5
 
                # find the coordinates of the points which will be used to compute the interpolation
                src_x0 = int(np.floor(src_x))
                src_x1 = min(src_x0 + 1 ,src_w - 1)
                src_y0 = int(np.floor(src_y))
                src_y1 = min(src_y0 + 1, src_h - 1)
 
                # calculate the interpolation
                temp0 = (src_x1 - src_x) * img[src_y0,src_x0,i] + (src_x - src_x0) * img[src_y0,src_x1,i]
                temp1 = (src_x1 - src_x) * img[src_y1,src_x0,i] + (src_x - src_x0) * img[src_y1,src_x1,i]
                dst_img[dst_y,dst_x,i] = int((src_y1 - src_y) * temp0 + (src_y - src_y0) * temp1)
 
    return dst_img
 
 
if __name__ == '__main__':
    img = cv2.imread('data/cat1.jpg')
    start = time.time()
    dst = bilinear_interpolation(img,(100,100))
    print 'cost %f seconds' % (time.time() - start)
    cv2.imshow('result',dst)
    cv2.waitKey()

            
          

References:
https://blog.csdn.net/xbinworld/article/details/65660665

https://blog.csdn.net/wudi_X/article/details/79782832

https://en.wikipedia.org/wiki/Bilinear_interpolation


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 国产一级二级三级 | 成人深夜视频 | 成人欧美视频在线观看 | 中文字幕中韩乱码亚洲大片 | 手机在线看片不卡中文字幕 | 国产精品毛片一区二区三区 | heyzo在线播放4k岛国 | 色中文字幕 | 香蕉视频在线看 | 国产日韩精品一区在线不卡 | 久久久精品2018免费观看 | 国产在线精品福利91香蕉 | 久久这里只有精品国产99 | 九九久久久久久久爱 | 成人a网 | 国产区在线观看 | 九九啪| 五月婷婷亚洲综合 | 日本高清在线精品一区二区三区 | 日韩欧美亚洲综合一区二区 | 一级a毛片免费观看 | 国产精品日韩欧美一区二区三区 | 亚洲 欧洲 自拍 另类 校园 | 12345国产精品高清在线 | 国产激情一级毛片久久久 | 九九99九九在线精品视频 | 国产露脸系列magnet | 久久天天躁夜夜躁狠狠85麻豆 | 综合九九| 久久久久在线观看 | 欧美日韩中文亚洲v在线综合 | 欧美妇性猛交视频 | 国产护士资源总站 | 久久久穴 | 日本一级在线播放线观看免 | 精品热久国产福利视频 | 亚洲高清国产一线久久 | 狠狠操天天爱 | 成年网站视频在线观看 | 淫视频在线观看 | 亚洲第一a|