【发布时间】:2018-03-22 07:23:10
【问题描述】:
我正在使用FreeMat,我有一张RGB 图片,它是一个 3D 矩阵,包含图片的列和行以及每个像素的 RGB 值。
由于没有将RGB图片转换为YIQ的内在函数,我已经实现了一个。我想出了这段代码:
假设我有一个 3D 数组,image_rgb:
matrix = [0.299 0.587 0.114;
0.596 -0.274 -0.322;
0.211 -0.523 0.312];
row = 1:length(image_rgb(:,1,1));
col = 1:length(image_rgb(1,:,1));
p = image_rgb(row,col,:);
%Here I have the problem
mage_yiq(row,col,:) = matrix*image_rgb(row,col,:);
max_y = max (max(image_yiq(:,:,1)));
max_i = max (max(image_yiq(:,:,2)));
max_q = max (max(image_yiq(:,:,3)));
%Renormalize the image again after the multipication
% to [0,1].
image_yiq(:,:,1) = image_yiq(:,:,1)/max_y;
image_yiq(:,:,2) = image_yiq(:,:,2)/max_i;
image_yiq(:,:,3) = image_yiq(:,:,3)/max_q;
我不明白为什么矩阵乘法会失败。我希望代码很好,而不仅仅是手动乘以矩阵...
【问题讨论】:
-
你了解矩阵乘法的原理吗?您如何解释收到的错误消息?在您必须解决的问题中,您实际上是在尝试将矩阵和 3D 数组相乘。顺便说一句:您可以使用 size(mat,n) 来获取 mat 沿维度 n 的大小,而不是 length(mat(:,1,1)) 或 length(mat(1,:,1))。并且 mat(1:size(mat,1),mat(1:size(mat,2),:) 与 mat(:,:,:) 相同,即与 mat 相同,即您的 p 相同作为 image_rgb。
标签: matlab image-processing freemat