I have a set of 100 jpg images named consecutively and I want to add them up to get a single image. I have seen the answer from here, but it does not run with me, what happened?
Here is the code:
im = imread('C:\Documents and Settings\1026175117_1.jpg');
for i = 2:10
im = imadd(im,imread(sprintf('C:\Documents and Settings\1026175117_%d.jpg',i)));
end
im = im/1000;
imshow(im,[]);
Here's the error message:
Error using ==> imread
Can't open file "C:" for reading;
you may not have read permission.
Backslash is a special character for sprintf() and needs to be escaped. Either use "\\" instead of "\" or try constructing your file paths another way. fullfile() is a good way to do it, so you only have to use sprintf for the file name part. Also see help sprintf.
Related
I have such a code;
for x = 1:100
path = sprintf('C:\Users\hasan_000\Documents\MATLAB\Project\Images\%d.jpg', x);
imgarray = imread(sprintf(path));
end
I have a folder involves 100 pictures. I want to convert them to matrix by uploading automatically in a loop.
But I get this error:
Can't open file "C:" for reading;
you may not have read permission.
How can I fix the problem?
Thanks,
The code should output the warning:
"Warning: Escape sequence '\U' is not valid. See 'help sprintf' for valid escape
sequences. "
You need to escape the \ when using sprintf. With yor code path is C:. For examples how proper escaping is done, please check the documentation for sprintf. Instead I would use this code:
P=fullfile('C:\Users\hasan_000\Documents\MATLAB\Project\Images',sprintf('%d.jpg',x))
imgarray = imread(P);
sprintf('C:\\Users\\hasan_000\\Documents\\MATLAB\\Project\\Images\\%d.jpg', x); should solve the issue.
sprintf('%s%d%s','C:\Users\hasan_000\Documents\MATLAB\Project\Images\',x,'.jpg');
is what I would suggest as it makes the code more intuitive and readable.
sprintf does not like your backslashes \ in the filename since it can be part of a specific command. If you simply run the path file you'll see:
path = sprintf('C:\Users\hasan_000\Documents\MATLAB\Project\Images\%d.jpg', 1);
path = C:
So that's where your code breaks. I'm currently not sitting on a windows machine, but I'd try reversing the slashes from backslashes \ to normal ones / and see if it can open that.
Second method works for sure:
path = ['C:\Users\hasan_000\Documents\MATLAB\Project\Images\', sprintf('%d.jpg', x)]
path = C:\Users\hasan_000\Documents\MATLAB\Project\Images\1.jpg
I am new to octave and need to plot a 2-D graph with customized title either as a file name or current directory name. I tried passing pwd in the plot.m file but it gives me a complete path instead of directory name only. Actually all I need is a customized title without manually hard coding the string inside xlabel('strings').
I don't have Octave but this works on MATLAB:
current_directory_name = pwd;
current_directory_split = regexp(current_directory_name,'/','split');
string_of_interest = current_directory_split(end);
xlabel(string_of_interest);
I am assuming you are on *NIX computer. For Windows computer, change / to \ in the split command.
If I understood your question correctly, you want a portable way of retrieving the file name w/o the directory name. Use fileparts():
[dir, name, ext, ver] = fileparts(pwd)
If you later decide to join strings, use filesep which is portable no matter if you're on Unix or not.
am trying to extract to use all my box file to extract characters and when i try this line
unicharset_extractor *.box
it gives me an error that it cannot find *.box instead of loading all box files.
That specific program does not support such syntax. You have to chain the names of all the box files and feed to it, such as:
unicharset_extractor lang.fontname.exp0.box lang.fontname.exp1.box ...
You can write a script (e.g., train.ps1) to automate the process.
http://code.google.com/p/tesseract-ocr/wiki/TrainingTesseract3
I finally made my own tool for that .
[link]http://code.google.com/p/serak-tesseract-trainer/
I try to write a image to a folder but imwrite has no input for specifying a folder name. Is there any other func. or way to store image to a folder. Maybe I amiss on imwrite if I do, I am sorry about it.
When I use a file name parameter like "folder1/folder2/img.jpg" it does not create folders accordingly and it just create a file named as "folder1/folder2/img.jpg"
I also try to use mkdir ahead in time but it also gives "Permission Denied" on console.
By the way I am using Linux. May be about permission problem?
The filename parameter doesn't mean just the name - you can give it a path, either absolute or relative, as part of the string.
imwrite(img,'my/folder/images/file','jpg')
for example.
The folder would just be specified in the file name, like this
imwrite(img, 'folder1/filename.tif','tif');
or if you want to use an absolute path.
imwrite(img, 'C:/Users/UserName/folder1/filename.tif','tif');
Check out wikipedia on absolute and relative paths.
If you want to write the image into destination folder use the following code in MATLAB.
destinationFolder = 'C:\Users\Deepa\Desktop\imagefolder';
if ~exist(destinationFolder, 'dir')
mkdir(destinationFolder);
end
baseFileName = sprintf('%d.png', i); % e.g. "1.png"
fullFileName = fullfile(destinationFolder, baseFileName);
imwrite(img, fullFileName); % img respresents input image.
I hope this answer might help someone.
this will open new figure to choose the path and format.
[filename, ext, user_canceled] = imputfile
I have a series of images saved in a folder, and I have written a short program to open two of these image files, concatenate them (preferably vertically, although for now I am trying horizontally), then save this new image to the same folder. This is what I have written so far:
function concatentateImages
%this is the folder where the original images are located path='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = strcat(cr45e__ch_21', '.pdf');
[image1,map1] = imread(graph1);
file2 = strcat('cr45f__ch_24', '.jpg');
[image2,map2] = imread(graph2);
image1 = ind2rgb(image1,map1);
image2 = ind2rgb(image2,map2);
image3 = cat(2,image1,image2);
%this is the directory where I want to save the new images
dircase=('/home/packremote/SharedDocuments/Amina/zEXAMPLE/');
nombrejpg=strcat(dircase, 'test', jpgext)
saveas(f, nombrejpg, 'jpg')
fclose('all');
However, I keep getting an error that my files do not exist, though I am certain the names are copied correctly.
I am currently using jpg files, but the format can be easily converted.
Any input on how to fix this error, or a nicer way of preforming this task is greatly appreciated!
Cheers,
Amina
Replace
[image1,map1] = imread(graph1);
and
[image2,map2] = imread(graph2);
by
[image1,map1] = imread(file1);
and
[image2,map2] = imread(file2);
Also check that you are in the right working directory.
In addition to the answer by #Simon, you also need to change
file1 = strcat(cr45e__ch_21', '.pdf');
to
file1 = strcat('cr45e__ch_21', '.pdf');
I.e. you forgot a '. Also your function doesn't seem to include a definition of jpgext. I expect you want a line like
jpgext = '.jpg';
Lastly, mostly a coding practice issue, but you might want to switch to using fullfile to build your full file path.
Also, instead of worrying about being in the correct working directory, if you use full paths you save yourself from having to keep track of what directory you're in.
SO I would suggest:
dir1 ='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = fullfile(dir1, 'cr45e__ch_21.pdf');
etc