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
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"?
iman kouadra
iman kouadra 2024년 4월 5일
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.

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

답변 (1개)

Samay Sagar
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:

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by