How to make this be a loop?

3 ビュー (過去 30 日間)
Jiajie Zhang
Jiajie Zhang 2018 年 11 月 29 日
コメント済み: Yixn Chen 2020 年 11 月 2 日
Hi, I want to make the function deal with a lot of images,
but I got errors when trying to add the loop.
The original one is:
imx = 'Images\20\IMG_4596.JPG',
Noisex = NoiseExtractFromImage(imx,2);
Noisex = WienerInDFT(Noisex,std2(Noisex));
% The optimal detector (see publication "Large Scale Test of Sensor Fingerprint Camera Identification")
Ix = double(rgb2gray(imread(imx)));
C = crosscorr(Noisex,Ix.*Fingerprint);
detection = PCE(C)
And I add a loop like this
file_path = 'Images\20\';
img_path_list = dir(strcat(file_path,'*.jpg'));
img_num = length(img_path_list);
if img_num > 0
for j = 1:img_num
image_name = img_path_list(j).name;
I = imread(strcat(file_path,image_name));
fprintf('%d %d %s\n',j,img_num,strcat(file_path,image_name));
imx(j).name = strcat(file_path,image_name);
Noisex{j} = NoiseExtractFromImage(imx(j).name,2);
Noisex(j) = WienerInDFT(Noisex(j),std2(Noisex(j)));
% The optimal detector (see publication "Large Scale Test of Sensor Fingerprint Camera Identification")
Ix(j) = double(rgb2gray(imread(imx(j).name)));
C(j) = crosscorr(Noisex(j),Ix(j).*Fingerprint);
detection(j) = PCE(C(j))
end
end
But I get an error :
Unable to perform assignment because brace indexing is not supported for variables of this type.
Error in Example (line 39)
Noisex{j} = NoiseExtractFromImage(imx(j).name,2);
Does anyone know how to make it right?
I'm new to matlab,
Thank you so much!
  1 件のコメント
Yixn Chen
Yixn Chen 2020 年 11 月 2 日
Hey did you ever fix this? If yes do you mind sharing how :D

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

回答 (1 件)

Jan
Jan 2018 年 11 月 29 日
Start with simplifying your code:
file_path = 'Images\20\';
img_path_list = dir(fullfile(file_path,'*.jpg')); % Safer than STRCAT
img_num = length(img_path_list);
for j = 1:img_num
image_name = img_path_list(j).name;
image_file = fullfile(file_path,image_name);
I = imread(image_file);
fprintf('%d %d %s\n', j, img_num, image_file);
Noisex{j} = NoiseExtractFromImage(image_file, 2);
Noisex(j) = WienerInDFT(Noisex(j), std2(Noisex(j)));
% The optimal detector (see publication "Large Scale Test of Sensor Fingerprint Camera Identification")
Ix(j) = double(rgb2gray(I));
C(j) = crosscorr(Noisex(j),Ix(j) .* Fingerprint);
detection(j) = PCE(C(j))
end
Now this looks strange:
Noisex{j} = NoiseExtractFromImage(image_file, 2);
Noisex(j) = WienerInDFT(Noisex(j), std2(Noisex(j)));
You use curly and round parentheses for the same variable. NoiseExtractFromImage and WienerInDFT do not belong to Matlab's toolbox functions, so I cannot guess, what the outputs are. Please check this.
double(rgb2gray(I)) replies a matrix. Then assignign the output to the scalar Ix(j) should fail. Do you want a cell array? Then use curly braces: Ix{j} .
Prefer to pre-allocate the results before the loop. This is more efficient and the types of the variables are well defined.

Community Treasure Hunt

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

Start Hunting!

Translated by