How to assign a numeric value to a picture file?

5 views (last 30 days)
ok so im having a problem with converting a file to numeric value. i have used str2num and has given me no luck. what i want to do is basically make a picture file for example x.gif equal to 1. I have multiple .gif files and want to assign values to each .gif file. how would i do this? thanks.

Accepted Answer

Image Analyst
Image Analyst on 23 Apr 2014
Jack, we're not sure what you want. So you read in your gif file
myGif = imread('x.gif');
Now you have all the pixels in the myGif array. So what do you want to do with that? Assign all the values to 1?
myGif(:) = 1; % Assign all pixels a value of 1, erasing previous values.
Why would you want to do that???
To process a sequence of files, see the FAQ for code samples: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
  2 Comments
Image Analyst
Image Analyst on 24 Apr 2014
Jack, regarding your "Answer" how about this:
filenames = dir('*.gif')
for k = 1 : length(filenames)
filenames(k).number = k;
end
Now every filename has a number associated with it. Of course it's just the same as the index so it's totally unnecessary, but it seems like that's what you want for some reason.
Jack
Jack on 28 Apr 2014
THANKS A LOT! I have used your first function using imread for the .gif file and using myGif=1 to assign 1 to the file. It works without the (:) so I don't see any multiple numbers. Easier than I thought as I was using imread to read all my .gif files but didn't want to do that for all my files so instead I used a directory function to read all the .gif files and helped me save a lot of time without doing imread for all files. But apparently, I have to use imread for each file now to assign a value as I cannot grab individual files from my directory function and assign values. Then again, it accomplishes what I want. Thanks again.

Sign in to comment.

More Answers (2)

Jack
Jack on 24 Apr 2014
I have used the directory function to put all my .gif files into an array. I want to recall them and given them a value. For example my array is reading like this x=[x.gif; y.gif; etc.] A 1x15 array. I want to be able to make it so x.gif is equal to 1 if I recall it back. So I guess something like x=[1; 2; etc] where x.gif is now 1. I've tried doing x=str2num(1;2). I have a=x.gif and b=y.gif and when I add them a column numbers is shown. I want it so it would be 1+2=3 when I recall the .gif files and add or subtract them. Idk if its possible but thanks for the replies.

Jack
Jack on 24 Apr 2014
I will try what you guys have suggested. Thanks. And basically I have card files and want to assign the value they represent like ace is 1 or 11 and king is 10.

Categories

Find more on File Operations 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!