How to convert a uint8 image to complex double?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gulfam Saju
am 17 Feb. 2023
Kommentiert: Walter Roberson
am 17 Feb. 2023
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 Kommentare
Walter Roberson
am 17 Feb. 2023
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
Akzeptierte Antwort
Sulaymon Eshkabilov
am 17 Feb. 2023
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 Kommentare
Walter Roberson
am 17 Feb. 2023
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!