the following code read images from the data base ''ORL data base'' To be processed and stored in another file, no errors but it don't work well?
3 ビュー (過去 30 日間)
古いコメントを表示
source_folder ='C:\Users\lio\Documents\MATLAB\ORL data base';
target_folder = 'C:\Users\lio\Documents\MATLAB\imanne';
tic;
if ~exist(target_folder, 'dir')
mkdir(target_folder);
end
subfolders = dir(source_folder);
subfolders = subfolders(arrayfun(@(x) x.isdir && ~strcmp(x.name, '.') && ~strcmp(x.name, '..'), subfolders));
for i = 1:length(subfolders)
subfolder_path = fullfile(source_folder, subfolders(i).name);
images = dir(fullfile(subfolder_path, '*.pgm'));
% Custom sorting function
[~, idx] = sort(arrayfun(@(x) sscanf(x.name, 's%d_%d.jpg'), images));
for j = 1:length(images)
% Read the image
gray_image = imread(fullfile(subfolder_path, images(idx(j)).name));
resizedImage = imresize(gray_image, [256, 256]);
% Perform your encryption
% Placeholder for encryption
im_crypt = encryptImage(resizedImage); % Replace 'encryptImage' with your encryption function
% Save the encrypted image
[~, name, ext] = fileparts(images(idx(j)).name);
encrypted_name = [name, '_encrypted', ext];
imwrite(abs(im_crypt), fullfile(target_folder, encrypted_name));
end
end
toc;
2 件のコメント
Venkat Siddarth Reddy
2024 年 4 月 4 日
Hi Iman,
To understand more about the performance issue, can you elaborate more on what do you mean by "dont work well"?
回答 (1 件)
Samay Sagar
2024 年 9 月 19 日
I can see that you are trying to read images from a directory and store them in a target directory after processing them.
However, the code you provided attemps to read PGM files but the the sorting function references JPG. Ensure that the file extensions are consistent. You also need to ensure that the encryptImage function is defined and works correctly.
You can also set breakpoints in your code to pause execution and inspect variable values. This will help you identify issues and understand why the results may not be as expected.
For more information about debugging, you can refer the following documentation:
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!