- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想为黑白图像添加颜色,我认为更改像素值应该可行。
for rows in rgb:
for e in rows:
for i in range(len(e)):
max_val = e.max()
min_val = e.min()
if e[i] == max_val:
e[i] * 2.5
if e[i] == min_val:
e[i] * 0.75
else:
e[i] * 1.5
代码没有返回错误,但它也没有改变值。我希望数字相乘并由同一个数组重新分配
最佳答案
我们可以利用 Numpy 的 broadcasting,而不是手动迭代具有低效 O(n^3)
运行时间的每个像素。功能。
我们首先使用 cv2.split()
将灰度图像分成单独的 BGR
channel .这将为我们提供单独的 B
、G
和 R
channel ,每个 channel 都具有相同的值。接下来我们使用 np.multiply()
将每个 channel 乘以一个标量值.最后,我们使用 cv2.merge()
将每个单独的 channel 组合成彩色图像。创建单个多 channel 阵列
之前
>>> print(before.shape)
(331, 500, 3)
您可能想知道为什么图像具有三个 channel ,即使它显然是灰度图像。这是因为每个 channel 都具有相同的值,范围从 [0 ... 255]
之后
>>> print(after.shape)
(331, 500, 3)
同样, channel 数量相同,但我们修改了每个单独的 channel
TLDR:要为黑白图像添加颜色,我们必须提取每个单独的 BGR
channel ,修改每个 channel ,然后重建图像
import cv2
import numpy as np
before = cv2.imread('2.png')
b, g, r = cv2.split(before)
np.multiply(b, 1.5, out=b, casting="unsafe")
np.multiply(g, .75, out=g, casting="unsafe")
np.multiply(r, 1.25, out=r, casting="unsafe")
after = cv2.merge([b, g, r])
cv2.imshow('before', before)
cv2.imshow('after', after)
cv2.waitKey()
关于python - 赋予灰度图像颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58135918/
有谁知道是否有办法在悬停时使图像灰度 - 除了创建 2 个单独的图像并更改 src 之外。 谢谢 编辑 - 半工作代码...: $(document).ready(function() {
我正在使用 flexbox 构建一个网站,其中包含 16x9 视频缩略图的 3 乘任意网格。我想在彩色缩略图变成单调(灰度 + x% 透明颜色层)的地方创建翻转,上面有一个白色 Logo 。 尽管我尽
现在泰国很多网站都是灰度的,大多使用-webkit-filter: grayscale(100%), filter: grayscale(100%)等。 我知道我们可以像往常一样“手动”(在 Chro
给定一张灰度的图像,我如何获得该位置的灰度像素值? 这始终将 temp 输出为 -16777216(黑色)。 public void testMethod() { int width = im
灰度化一个可绘制对象: ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(200); ColorMatrixColorFilte
我正在尝试创建一种悬停效果,其中图像以全彩色开始,当我将鼠标悬停在图像上时,我希望它有一个蓝色覆盖层。 事实是,只有一个简单的蓝色叠加层,它只是在彩色图像之上放置一个半透明的蓝色 block ……这意
将颜色 Drawable 转换为灰度的正确方法是什么(表示禁用状态)? 编辑: 黑白 => 灰度 最佳答案 我知道这个问题是不久前提出的,但我遇到了一个更简单的解决方案,如果你有一个 Drawable
我需要将 CMYK 图像转换为灰度 CMYK 图像。起初我以为我可以使用与 RGB -> 灰度转换相同的方法,比如 (R + G + B)/3 或 max(r, g, b)/2 + min(r, g,
我遇到了一些将 UIImage 更改为灰度的代码的问题。它可以在 iPhone/iPod 上正常工作,但在 iPad 上,任何已经绘制的内容都会在此过程中被拉伸(stretch)和扭曲。 它有时也只在
假设我有: int x = 140; 我想得到的结果: int y = new Color(x, x, x).getRGB() 来自 Java API 文档: getRGB() Gets the RG
我在我的论文中使用 opencv 用 c++ 编写了一个 block 匹配算法。它正在处理灰度图片并通过其绝对像素地址寻址 IPLImage。 我必须将 IPLImage 分成相同大小的 block
我有一个带有背景图像的 div,我正在使用过滤器以黑白方式显示它 (filter: grayscale(100%);)。我现在正试图在该 div 中放置一个颜色图标。尝试将图标设置为 grayscal
我会避免使用 cvtColor(frame, image, CV_RGB2GRAY); 转换摄像机拍摄的每一帧无论如何设置 VideoCapture 直接进入灰度? 例子: VideoCapture
我有一些 CSS 可以将我的图像变成灰度(带有一些用于 Firefox 的 svg) img.grayscale{ filter: grayscale(100%);
有没有什么方法可以在不丢失任何其他功能的情况下以灰度显示 Google map (通过 Javascript API 嵌入)? 最佳答案 是的,他们在 API 的 V3 中引入了 StyledMaps
我正在使用 Java Swing 制作桌面应用程序。 在我的应用程序中,我对 16 位灰度和 tiff 图像进行了一些图像处理。 在我的应用程序中,用户可以通过将图像拖放到 JDesktopPane
我正在为学校的一个项目执行此操作,稍后将添加更多功能,但我在完成基本设置时遇到了困难。 我最初尝试在 C++ 中执行此操作,但在阅读了有关 BufferedImage 的一些文档后决定切换到 Java
我使用 Canvas 更改网页上图像的颜色(本例为灰度)。但是,通过使用以下代码,仅更改了最后一张图像。 但我想更改网页上所有图像的颜色 $(function(){ var theI
首先我要警告你,我只是一个试图让事情发挥作用的物理学家,我对 C++ 的知识基本上是不存在的。 我目前正在使用 GATE 模拟 CT 扫描仪,我需要将输出转换为 bmp 文件。 Gate 制作了一系列
link 在 chrome 中,它运行完美。但是,在 Firefox 中,图像不会出现。 我已经设置了 SVG 的 mime 类型,并且 mime 类型检查器显示 mime 类型是正确的。 有人能帮帮
我是一名优秀的程序员,十分优秀!