how to link a word or group of words to a " *.jpg" picture.

2 views (last 30 days)
folder = 'F:\school\matlab\project\pictures\pictures alone'; files = {'apple.jpg','condor.jpg','elephant.jpg',... 'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg'};
i'm quiet new to this programming thing.. so i'm trying to learn more about programming and matlab...
is there a way to link different words to each ".jpg' picture in that array...? i have a feeling that it might be possible but i just don't know how...
here is my array of pictures... but i dont know how to link the words that i like to each picture...
like say, i would like the word apple to be linked with 'apple.jpg' so that when i see the apple picture and i type apple it will give me a positive response... i have been searching the web about this.. and i cant find a way to do it... well i might had already found the answer but i probably didn't understand it... i'm sorry if i'm being too demanding.. just wanted to explore this matlab programming.. coz it's my first time to do programming.... and i'm very excited to try lots of things with this....

Accepted Answer

Guillaume
Guillaume on 23 Mar 2015
This is a copy of the answer I wrote in the comment to my answer of your other question:
It sounds like you're after a method of tagging pictures and retrieving / searching these tags.
This is normally done with a database or some data structures that are not available in matlab (e.g. multi-index container). In matlab, what I would do is use a map.
If you wanted to make it easy to find images associated with a certain tag, the tags would be the keys, the images associated with the tag, the values, would be a cell array:
keys = {'fruits', 'animals', 'apples', 'birds'};
values = {{'apple.jpg', 'orange.jpg'}, {'condor.jpg', 'elephant.jpg', 'koala.jpg', 'whale.jpg', 'penguins.jpg'}, {'apple.jpg'}, {'condor.jpg', 'penguins.jpg}};
tagimages = containers.Map(keys, values);
%find images of birds:
birdimages = tagimages('birds')
%add a tag:
tagimages('Four legged') = {'elephant.jpg', 'koala.jpg'}
The issue with the above is that you duplicate the image strings a lot in the map (that can be worked around by storing indices to the cell array of filenames instead) and finding the tags associated with one image is not easy. Matlab unfortunately does not have a great deal of containers. To get something better, you'd have to use the database toolbox.
If what you want to do predominantly is find tags associated with an image, then you make the images the keys, and the tags the values:
keys = {'apple.jpg', 'orange.jpg', 'condor.jpg', 'elephant.jpg', 'koala.jpg', 'whale.jpg', 'penguins.jpg'};
values = {'fruit', 'apple'}, {'fruit'}, {'animal', 'bird'}, {'animal'}, {'animal'}, {'animal'}, {'animal', 'bird'}};
imagetags = containers.Map(keys, values);
appletags = imagetags('apple.jpg')

More Answers (2)

Stephen23
Stephen23 on 23 Mar 2015
Edited: Stephen23 on 23 Mar 2015
One of the easiest ways to achieve this in MATLAB simply uses two cell arrays and an index to pick the corresponding data each of them. In your case you could do something like this:
files = {'apple.jpg','condor.jpg','elephant.jpg',... 'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg'};
words = {{'apple','fruit'},{'condor','bird'},{'elephant','mammal'},...,{'whale','mammal'},{'penguin','bird'}};
then you can pick the same elements of both matrices simply by using an index, in this case I used 2 to pick the second element:
>> files{2}
ans = 'condor.jpg'
>> words{2}
ans = {'condor','bird'}
Another way would be to use structures, which allow key-value lookup, like a dictionary. You could use a non-scalar structure, which would be similar to above except with the advantages that all of the data would be kept in one structure and the fieldnames make it clearer what the data refers to:
data(2).file = 'condor.jpg';
data(2).word = {'condor','bird','wings'};
Another way to use a structure would be to use the names as the keys, like this, which might make accessing the data easier:
data.condor = {'condor','bird','wings'}
Note that you can also dynamically generate the field names. The field names must only contain alphanumeric or underscore characters.
You can match words using strcmp, or strcmpi, and locate substrings using strfind.

Shantanu Jana
Shantanu Jana on 23 Mar 2015
Specify descriptive text to associate with image acquisition object acn solve your problem. check this link it describe how to associate tag and other information to a image

Categories

Find more on Get Started with MATLAB 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!