Multiple Image reconstruction with real and imaginary part in 2d array

4 ビュー (過去 30 日間)
Shourya
Shourya 2022 年 9 月 22 日
コメント済み: Shourya 2022 年 9 月 27 日
I have two mat files one with real and another with imaginary part of 500 images. I am using the following line to reconstruct a single image :
" imshow(reshape(sqrt(a_imag(:,i).^2+a_real(:,i).^2),[128,128]) "
Each mat file is a 2D array (16384x500) with grayscale images of size 128x128. 'i' indiactes the image/column number.
I am trying to reconstruct all the 500 images and save each of them in .jpg format in the same order from 1-500. I tried this code and I am recieving an error.
a_real = load("img_real.mat");
a_imag = load("img_imag.mat");
for i = 1 : 500
I(:,i) = reshape(sqrt(a_imag(:,i).^2+a_real(:,i).^2),[128,128]);
end
save('image', num2str(i),'.jpg');
Error:
Operator '.^' is not supported for operands of type 'struct'.
Error in image_recon (line 6)
I(:,i) = reshape(sqrt(a_imag(:,i).^2+a_real(:,i).^2),[128,128]);

採用された回答

Matt J
Matt J 2022 年 9 月 22 日
編集済み: Matt J 2022 年 9 月 22 日
What is the name of the variable stored inside the .mat files? If I assume it is X, then,
a_real = load("img_real.mat").X;
a_imag = load("img_imag.mat").X;
  9 件のコメント
Matt J
Matt J 2022 年 9 月 25 日
編集済み: Matt J 2022 年 9 月 25 日
a_real = load("img_real.mat").img_real;
a_imag = load("img_imag.mat").img_imag;
I = reshape( sqrt(a_imag.^2+a_real.^2), 128,128,[]);
N=size(I,3);
filenames="image"+(1:N)+".jpg";
for i=1:N
imwrite(I(:,:,i),filenames(i));
end
a = imread('image99.jpg');
Shourya
Shourya 2022 年 9 月 27 日
@Matt J Thank you this worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by