access to each image channel existing in a folder

조회 수: 2 (최근 30일)
assia assia
assia assia 2021년 6월 30일
댓글: assia assia 2021년 6월 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
Yongjian Feng
Yongjian Feng 2021년 6월 30일
Is it a black and white image?
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:
  댓글 수: 3
Jan
Jan 2021년 6월 30일
Stokes{1}(:, :, 3)
assia assia
assia assia 2021년 6월 30일
Thank you for your help.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by