필터 지우기
필터 지우기

How to convert a uint8 image to complex double?

조회 수: 4 (최근 30일)
Gulfam Saju
Gulfam Saju 2023년 2월 17일
댓글: Walter Roberson 2023년 2월 17일
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
Gulfam Saju
Gulfam Saju 2023년 2월 17일
It can be calculated using the two matlab functions:
real(Img);
imag(Img);
Walter Roberson
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)
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

댓글을 달려면 로그인하십시오.

채택된 답변

Sulaymon Eshkabilov
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
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 17일
Most welcome!
Walter Roberson
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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by