access to each image channel existing in a folder

2 Ansichten (letzte 30 Tage)
assia assia
assia assia am 30 Jun. 2021
Kommentiert: assia assia am 30 Jun. 2021
Hello folks,
I'm trying to access to each image channel existing in the folder and calculate after PSNR and SSIM of each channel. I developped this code but I still have an error to access to each image channel. Any idea to make it work please.
imgFolderStokes = fullfile('saveAssia/StokesPaarameters/');
imgFolderLinear = fullfile('saveAssia/Linear_Separable_Model/');
imgStokes = imageDatastore(imgFolderStokes);
imgLinear = imageDatastore(imgFolderLinear);
numOfImgStokes = length(imgStokes.Files);
numOfImgLinear = length(imgLinear.Files);
for ii = 1:numOfImgStokes
for jj = 1:numOfImgLinear
Stokes{ii} = fitsread(imgStokes.Files{ii})
Linear{jj} = fitsread(imgLinear.Files{ii})
Iu_s = Stokes(:,:,1);
Ip_s = Stokes(:,:,2);
Theta_s = Stokes(:,:,3);
Iu_L = Linear(:,:,1);
Iu_L = imresize( Iu_L,[size(Iu_s,1) size(Iu_s,2)]);
Ip_L = Linear(:,:,2);
Theta_L = Linear(:,:,3);
[ssim] = ssim(uint8(Iu_s),uint8(Iu_L));
[psnr] = psnr(uint8(Iu_s),uint8(Iu_L));
end
end
avr_peaksnr = sum([psnr]) / len([psnr])
avr_snr = sum([ssim]) / len([psnr])
fprintf('\n The Peak-SNR value is %0.4f', avr_peaksnr);
fprintf('\n The SNR value is %0.4f \n', avr_snr);
ERROR
Index in position 3 exceeds array bounds (must not exceed 1).
Error in PSNR_SSIM (line 96)
Ip_s = Stokes(:,:,2);
  4 Kommentare
Yongjian Feng
Yongjian Feng am 30 Jun. 2021
Is it a black and white image?
assia assia
assia assia am 30 Jun. 2021
Bearbeitet: assia assia am 30 Jun. 2021
The first one has a 3 channels and the second one has 6 channels
Stokes =
1×1 cell array
{300×300×3 double}
Linear =
1×1 cell array
{234×244×6 double}

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Jun. 2021
Bearbeitet: Image Analyst am 30 Jun. 2021
Evidently
Error in PSNR_SSIM (line 96)
Ip_s = Stokes(:,:,2);
means that there is no third dimension to your Stokes array. The third dimension has a max of 1, basically meaning there is no third dimension. It's a gray scale monochrome image, not a RGB color, or multispectral, or volumetric image with multiple slices along the third (Z) dimension.
In fact, Stokes is not an image at all - it's a cell array because you did this:
Stokes{ii} = fitsread(imgStokes.Files{ii})
so it's a cell array - a 1-D array of cells. Inside each cell may be an image but you have to use braces to get to it:
thisImage = Stokes{ii}; % Get contents of cell.
See the FAQ:
  3 Kommentare
assia assia
assia assia am 30 Jun. 2021
Thank you for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by