How to convert a uint8 image to complex double?

10 visualizaciones (últimos 30 días)
Gulfam Saju
Gulfam Saju el 17 de Feb. de 2023
Comentada: Walter Roberson el 17 de Feb. de 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 comentarios
Gulfam Saju
Gulfam Saju el 17 de Feb. de 2023
It can be calculated using the two matlab functions:
real(Img);
imag(Img);
Walter Roberson
Walter Roberson el 17 de Feb. de 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)
ans = 75
ans = 0
Ari = complex(Ar, Ai);
whos A Ar Ai Ari
Name Size Bytes Class Attributes A 5x5x3 75 uint8 Ai 5x5x3 75 uint8 Ar 5x5x3 75 uint8 Ari 5x5x3 150 uint8 complex
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
Name Size Bytes Class Attributes Aid 5x5x3 600 double Ard 5x5x3 600 double Arid 5x5x3 1200 double complex Arid_plus 5x5x3 600 double

Iniciar sesión para comentar.

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 17 de Feb. de 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 comentarios
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 17 de Feb. de 2023
Most welcome!
Walter Roberson
Walter Roberson el 17 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by