matrix dimensions must agree error

1 次查看(过去 30 天)
%I want to use dct2 to an image array and quantize 4x4 blocks of the image
%but in [afteral]=quantization(imafter,25); command it says "matrix dimensions must agree"
%IGNORE integer_transform its just another function I use.
frame178=imread("frame178.tif");
quantize = @(block_struct) integer_transform(dct2(block_struct.data));
imafter = blockproc(frame178,[4 4],quantize);
[afteral]= quantization(imafter,25);
%the function :
function [Z] = quantization(W,QP)
Z = round(W.*(M/2^q));
%THIS IS THE FUNCTION DEFINITION AND THE LINE WHERE IS THE ERROR
%M and q are defined before in the function M is a matrix with some factors and q is an integer
%I assume Z the error is the inserted matrix M that is different size from Z but when I do
%multiply with x.*y dont I multiply all elements of an array(W) with an integer from a matrix(M)? so why to have size error there?

采纳的回答

Image Analyst
Image Analyst 2019-11-22
编辑:Image Analyst 2019-11-22
It's not Z that matters. It's W.
What does this report in the command window if you put it before that Z line:
whos W
whos M
whos q
  2 个评论
Lefteris Kostakis
Lefteris Kostakis 2019-11-22
W 144x176 double (the parameter in function is array frame178 and its also 144x176 but not double it is uint8)
M 4x4 double
q 1x1 double
Image Analyst
Image Analyst 2019-11-22
So why do you think it's okay to do an element-by-element operation of a 144x176 matrix by a 4x4 matrix?
What happens when it goes to multiply W(5, 1) by M(5, 1) when there is no M(5,1)?
It can't multiply elements when the elements are not there.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by