【发布时间】:2020-07-30 02:54:19
【问题描述】:
我正在做一门课程,他们有示例示例,可以读取图像并创建 20.20 pix。 有 rgb2ntsc 但在最新版本的 Octave 中不可用。 什么可以替代它?
【问题讨论】:
标签: octave data-analysis
我正在做一门课程,他们有示例示例,可以读取图像并创建 20.20 pix。 有 rgb2ntsc 但在最新版本的 Octave 中不可用。 什么可以替代它?
【问题讨论】:
标签: octave data-analysis
我不知道下面是否回答了你的问题,但我编写了代码,使用source:
function yiq_img = rgb2ntsc(rgb_img)
%RGB2NTSC Transform a colormap or image from red-green-blue (RGB)
% color space to luminance-chrominance (NTSC) space.
% The input may be of class uint8, uint16, single, or double.
% The output is of class double.
% https://octave.sourceforge.io/octave/function/rgb2ntsc.html
if isa(rgb_img, 'uint8') || isa(rgb_img, 'uint16') || ...
isa(rgb_img, 'double')
red = rgb_img(:, :, 1);
green = rgb_img(:, :, 2);
blue = rgb_img(:, :, 3);
y = 0.299 * red + 0.587 * green + 0.114 * blue;
i = 0.596 * red - 0.274 * green - 0.322 * blue;
q = 0.211 * red - 0.523 * green + 0.312 * blue;
yiq(:, :, 1) = y;
yiq(:, :, 2) = i;
yiq(:, :, 3) = q;
yiq_img = double(yiq);
else
error('Input image datatype is not supported')
end
end
如何确保代码正常工作?
例子:
>>> I = rgb2ntsc(imread('samur.jpeg'));
>>> imshow(I)
在哪里
转换为:
【讨论】:
函数rgb2ntsc 历史上一直是 Octave 的一部分(我的意思是历史上,自 1994 年以来)。但是,自 Octave 4.4 版(2018 年发布)以来,该功能已从 Octave 移至 Octave Forge 映像包。自 2.8.0 版本(2018 年发布)以来,它就是 Octave Forge 映像包的一部分。
基本上rgb2ntsc的使用方法取决于你的版本:
需要安装并加载2.8.0或更高版本的镜像包(最新为2.12.0)。
octave> pkg install -forge image
octave> pkg load image
您无需执行任何操作,rgb2ntsc 已经可用。
【讨论】:
rgb2ntsc是图片包的功能
https://octave.sourceforge.io/image/function/rgb2ntsc.html
要使用它,请加载 image 包(如果已安装)
octave:2> pkg load image
octave:3> help rgb2ntsc
'rgb2ntsc' is a function from the file /usr/share/octave/packages/image-2.12.0/rgb2ntsc.m
-- YIQ_MAP = rgb2ntsc (RGB_MAP)
-- YIQ_IMG = rgb2ntsc (RGB_IMG)
Transform a colormap or image from red-green-blue (RGB) color space
to luminance-chrominance (NTSC) space. The input may be of class
uint8, uint16, single, or double. The output is of class double.
Implementation Note: The reference matrix for the transformation is
/Y\ 0.299 0.587 0.114 /R\
|I| = 0.596 -0.274 -0.322 |G|
\Q/ 0.211 -0.523 0.312 \B/
as documented in <http://en.wikipedia.org/wiki/YIQ> and truncated
to 3 significant figures. Note: The FCC version of NTSC uses only
2 significant digits and is slightly different.
See also: ntsc2rgb, rgb2hsv, rgb2ind.
【讨论】: