图片黑客帝国化

community_850 2021-12-17 23:27:21

黑客帝国的图片风格偏绿色,任意图片的每个像素(r,g,b)经过公式转换后即可获得一张“黑客帝国风格图片”:

  • r = r3/2
  • g = r4/5
  • b = r3/2

我们对lena图片也做黑客帝国风格化处理:

框架代码如下:

import numpy as np
import cv2
import math

def hacker(img):
    # TODO(You): 请在此添加代码

if __name__ == '__main__':
    img_origin = cv2.imread('lena.png', cv2.IMREAD_COLOR)
    img = cv2.imread('lena.png', cv2.IMREAD_COLOR)
    print(img.size)
    print(img.shape)

    hacker(img)

    print('显示图片,请按任意键退出')
    numpy_horizontal_concat = np.concatenate((img_origin, img), axis=1)
    cv2.imshow('Lena图片黑客帝国化', numpy_horizontal_concat)
    cv2.waitKey()
    cv2.destroyAllWindows()

以下选项是对函数 def hacker(img) 的实现,请选出实现有错的选项。

...全文
655 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复 8

题目有问题,都不对;
索引有问题。请出题官仔细审核;
取像素的时候,i, j 搞反了。

  • 打赏
  • 举报
回复 2
import math

def hacker(img):
    height, width, channels = img.shape
    for i in range(0, width):
        for j in range(0, height):
            b, g, r = img.item((i, j))
            hack_b = int(math.pow(b/256.0, 3/2) * 256)
            hack_g = int(math.pow(g/256.0, 4/5) * 256)
            hack_r = int(math.pow(r/256.0, 3/2) * 256)
            img.itemset((i, j), (hack_b, hack_g, hack_r))
大为慎独 2022-01-15
  • 打赏
  • 举报
回复 4
黑客帝国的图片风格偏绿色,任意图片的每个像素(r,g,b)经过公式转换后即可获得一张“黑客帝国风格图片”:

r =  r^3/2
g = g^4/5
b = b^3/2

21

社区成员

发帖
与我相关
我的任务
社区管理员
  • community_850
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧