Sir plz help me to rectify this error

1 次查看(过去 30 天)
X=reshape(x,size(Y));
where x=1; and Y=256 * 256 uint8
I got the error like this
"To RESHAPE the number of elements must not change."

采纳的回答

Image Analyst
Image Analyst 2016-8-6
Since x=1, you can use ones():
X = ones(size(Y)); % X is a double
If x is not one, but some other scalar, then you can use.
X = x * ones(size(Y)); % X is a double
If you want X to also be uint8, pass that class in:
X = ones(size(Y), 'uint8'); % Now X will also be uint8

更多回答(1 个)

Walter Roberson
Walter Roberson 2016-8-6
You cannot reshape a scalar into a 256 by 256 matrix. reshape() cannot create new data.
Perhaps you want
X = repmat(x, size(Y));

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by