access to each image channel existing in a folder

2 visualizaciones (últimos 30 días)
assia assia
assia assia el 30 de Jun. de 2021
Comentada: assia assia el 30 de Jun. de 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 comentarios
Yongjian Feng
Yongjian Feng el 30 de Jun. de 2021
Is it a black and white image?
assia assia
assia assia el 30 de Jun. de 2021
Editada: assia assia el 30 de Jun. de 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}

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Jun. de 2021
Editada: Image Analyst el 30 de Jun. de 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 comentarios
Jan
Jan el 30 de Jun. de 2021
Stokes{1}(:, :, 3)
assia assia
assia assia el 30 de Jun. de 2021
Thank you for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by