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 views (last 30 days)
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 Comments
Venkat Siddarth Reddy
Venkat Siddarth Reddy on 4 Apr 2024
Hi Iman,
To understand more about the performance issue, can you elaborate more on what do you mean by "dont work well"?
iman kouadra
iman kouadra on 5 Apr 2024
hi Venkat Siddharth Reddy,
thank you for your ansewer.
When I run this code it creates a new folder to store the processed images but it doesn't (can't)start reading the elements of the database automatically, but when I read an image randomly from the database it can be processed and stored in this new file.

Sign in to comment.

Answers (1)

Samay Sagar
Samay Sagar on 19 Sep 2024
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:

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!