Save a group of processed imags output from a for loop in a specific folder

Hello,
I have an image database, i process them through a for loop, i want to save the output processed images in anther folder, i have the following error when i trying to do that:
Error using imwrite
unable to open file " ********.bmp" for writing. you might not have write permission
the code i have used is:
SNLImagepath='F:\SNL_images\';
FileName = fullfile(savepath, sprintf(ImageName,ext));
imwrite(a, FileName);

 Accepted Answer

You gave the wrong path. "savepath" is a built in function, and you're trying to call it when you call fullfile()! You should pass in SNLImagepath, not savepath. Plus you're calling sprintf() incorrectly -- you didn't give it a specification string.
Try this:
SNLImagepath='F:\Biometrics\Eman\Eman_test_SNL_Gabor\SNL_images'
FileName = fullfile(SNLImagepath, sprintf('%s%s', ImageName,ext));
imwrite(a, FileName);

3 Comments

Ooooh, thanks it works correctly now.
But I do not need to use the specification string with sprintf(). Matlab sees the '%' sign as a comment, plus it shows that it's enough to use two parameters to call it.
MATLAB does NOT see the % symbol as a comment when it's embedded in a string, like I did here. You might want to learn how to use format specifier strings since it's common to all programming languages. That's the protocol where you use %, some numbers, and a letter that indicates the variable type (f, d, s, etc.).
Iam sorry, i didnot notice the single comma befor and after % sign, it appears that is the reason of the error i have.
Thanks again.

Sign in to comment.

More Answers (1)

Have you correctly given the permission to the folder you are writing?
Once try this,
savepath = 'C:\Some_dir\Some_folder';
FileName = fullfile(savepath, sprintf(ImageName,ext));
imwrite(a, FileName);

3 Comments

i already tried many forms like this, it not work too
the error still appears:
SNLImagepath='F:\Biometrics\Eman\Eman_test_SNL_Gabor\SNL_images'
FileName = fullfile(savepath, sprintf(ImageName,ext));
imwrite(a, FileName);
Error using imwrite (line 467)
Unable to open file " \0001_0001.bmp" for writing. You might not have write permission.
Error in mainFile_finaltree (line 7843)
imwrite(a, FileName);
you need to edit the line
FileName = fullfile(SNLImagepath, sprintf(ImageName,ext));

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 9 Nov 2019

Commented:

on 12 Nov 2019

Community Treasure Hunt

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

Start Hunting!