How to convert a uint8 image to complex double?
10 次查看(过去 30 天)
显示 更早的评论
I want to convert a png file into a complex valued number. The current dimension and format of the png file is:
320x320x3 uint8
I want to convert into the format like the format below:
320x320 complex double
When I use the
A = imread("01.png");
Img = im2double(A);
The output comes as:
320x320x3 double
But I want the third dimension to be removed and merge into 320x320.
3 个评论
Walter Roberson
2023-2-17
An array that shows up as 320x320x3 uint8 is not complex-valued
A = randi([1 255], [5 5 3], 'uint8');
Ar = real(A);
Ai = imag(A);
nnz(Ar), nnz(Ai)
Ari = complex(Ar, Ai);
whos A Ar Ai Ari
Notice that A, the original image, does not show up as complex, and the the number of non-zero complex parts of it was zero. You can deliberately put a complex layer onto it, but as soon as any math is done on it, it will strip off the all-zero complex layer
Ard = im2double(Ar);
Aid = im2double(Ai);
Arid = complex(Ard, Aid);
Arid_plus = Arid + 0;
whos Ard Aid Arid Arid_plus
采纳的回答
Sulaymon Eshkabilov
2023-2-17
One of the dimensions can be removed using squeeze() fcn or taking averaged pixel values from R, G, B layers:
D = imread('01.png');
Dd = im2double(D);
Ds = squeeze(Dd(:,:,1)); % Red layer is considered
DD = mean(Dd, 3); % Averaged pixel values computed from Red, Green, Blue
3 个评论
Walter Roberson
2023-2-17
The squeeze() is not doing anything useful there in creating Ds. Also, Ds is not used afterwards.
This code creates DD as the mean of R, G, and B (which, by the way, is not what you would do to convert to grayscale), but DD will not be complex.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!