access to each image channel existing in a folder

2 次查看(过去 30 天)
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 个评论
assia assia
assia assia 2021-6-30
编辑:assia assia 2021-6-30
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}

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2021-6-30
编辑:Image Analyst 2021-6-30
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:

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by