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!