How do I assign a number to an image in a cell array?

조회 수: 5 (최근 30일)
Rupert Steinmeier
Rupert Steinmeier 2020년 10월 8일
편집: Jon 2020년 10월 26일
Hi guys!
I have a 1x40 cell array with 40 images ({'1.jpg'},{'2.jpg'}...and so forth). And I want to assign certain numbers to certain images because these numbers stand for certain chracteristics of the images (gender, identity, facial expression....). I need these numbers for a randomization.
So, does somebody know how to assign numbers to the images of a cell array?
Thanks in advance!
Best,
R
  댓글 수: 1
KSSV
KSSV 2020년 10월 8일
Simple..you define the numbers in a 1*40 array. Where each index corresponds to respetive image.

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

답변 (1개)

Jon
Jon 2020년 10월 8일
편집: Jon 2020년 10월 8일
If you have a number of characteristics and don't want to have some elaborate encoding for how these are all specified I would put the data into a table with a column for the images (your current cell array) and then additional columns for each characteristic of interest. You could then easily access the data according to the rows that have the charactertics that match the ones of interest. Type doc table on the command line for details about how to create a table. Here is an overview of using tables https://www.mathworks.com/help/matlab/matlab_prog/advantages-of-using-tables.html
Another way to do this, if you just had a single characteristic encoded as a number to go with each image would be just to make a vector with the same number of elements as your cell array and store the characteristics in the elements of this vector. Lets call the vector of characteristics, imageCharacteristics, and the cell array of image, images. Then if you wanted for example to set the imageCharacteristics corresponding to the 4th image in your cell array to a value of 232 (just making up something for the example) you could assign
imageCharacteristics(4) = 232
later if you wanted the image and its characteristics you could open up
image = images{4}
imageCharacteristic = imageCharacteristic(4)
Still I would recommend putting the data into a table as a good general approach
  댓글 수: 8
Rupert Steinmeier
Rupert Steinmeier 2020년 10월 17일
You are right, it is a pseudo-random sequence.
The idea is that we are keeping track of the stimulus pairings (con-con and so forth), the age, the gender, the facial expressions and the identity of the stimuli. So we can tell Matlab to draw again from the stimuli pool if the drawn stimulus has the same identity as the preceding one for example.
But in order to do so, we need to assign these features to the stimuli (for example with the table you suggested). And then we have to be able to compare the features of the stimuli with numeric values. For example: If identity of first image in the sequence == 1 then identity of second image ~= 1. And so forth.
So, this leads me back to my question: Do you know how to compare the features of the stimuli in the table with numeric values?
Best,
R
Jon
Jon 2020년 10월 26일
편집: Jon 2020년 10월 26일
I've been away from the computer for awhile. Maybe you've already solved your problem. If not here are some further ideas.
If you have the images and their features in a table, let's call it T, you can draw a random row from the table using
sample = T(randi(numImages),:) % numSample is total number of images
note that sample is itself a table with just one row but you can access the various features using dot notation.
Suppose also that you had already saved your previous sample as lastSample (also a one row table)
So if your column names (variable names ) were imFile, id, con, gender, expression, age and you wanted to make sure that the sample was a different subject, and gender than the last one (just for example) you could then check
isGood = sample.id ~= lastSample.id && sample.gender~=lastSample.gender
if its good you can get the name of the image file and present it and then set your lastSample equal to your current sample
So I guess you would have a loop something like
% you will have to do some initialization here before entering loop
% ...
numPresented = 0
lastSample = T(randi(numImages),:) % random last sample just to initialize
% enter loop
while numPresented < numRequired
% draw a sample
sample = T(randi(numImages),:) % numSample is total number of images
% check criteria
% the ones below are just for illustration, you can set what you need in a similar way
isGood = sample.id ~= lastSample.id && sample.gender~=lastSample.gender
if isGood
image = sample.imFile; % and then show it to the user
% save the last sample for comparison
lastSample = sample
numPresented = numPresented + 1
end
end

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by