How to plot an intensity graph?
Show older comments
I have obtained an average value of red pixel count as well the time involved. How do I plot an intensity graph?
Answers (1)
Walter Roberson
on 11 Jan 2016
plot(t, average_red_value_vector);
xlabel('time');
ylabel('Intensity');
10 Comments
Gee Cheng Mun
on 11 Jan 2016
Walter Roberson
on 11 Jan 2016
t = 320:400; %if consecutive integers
Gee Cheng Mun
on 12 Jan 2016
Edited: Gee Cheng Mun
on 12 Jan 2016
Walter Roberson
on 12 Jan 2016
average_red_value_vector should be the vector of averages, however you obtain them. This would require that you have multiple things you were averaging together at each time, which is certainly a possibility, but I wonder if what you have instead is the counts, something like
dinfo = dir('ghostkidney_*.tiff');
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
thisimage = imread(thisfile);
meets_red_threshold = thisimage(:,:,1) > 180 & thisimage(:,:,2) < 60 & thisimage(:,:,3) < 60; %strong red compared to G or B
red_counts(K) = nnz(meets_red_threshold);
t(K) = (K-1)/24; %24 frames per second
end
plot(t, red_counts)
Gee Cheng Mun
on 12 Jan 2016
Edited: Gee Cheng Mun
on 12 Jan 2016
Walter Roberson
on 12 Jan 2016
Edited: Walter Roberson
on 12 Jan 2016
projectdir = fullfile(pwd, 'MyProject'); %or use an absolute path
folder_info = dir(projectdir);
folder_info(~[folder_info.isdir]) = []; %ignore non-folders
folder_info( ismember({folder_info.name}, {'.', '..'}) ) = []; %remove . and .. directories
num_folders = length(folder_info);
avg_counts = zeros(1, num_folders);
folder_times = zeros(1, num_folders);
for fold_idx = 1 : num_folders
this_folder = fullfile( projectdir, folder_info(fold_idx).name );
folder_times(fold_idx) = ... you didn't say how you know the time
file_info = dir( fullfile(this_folder, '*.tiff') ); %example image name pattern
num_files = length(file_info);
red_count = 0;
for file_idx = 1 : num_files
thisfile = fullfile(this_folder, file_info(file_idx).name );
thisimage = imread(thisfile);
%determine which pixels count as red
meets_red_threshold = thisimage(:,:,1) > 180 & thisimage(:,:,2) < 60 & thisimage(:,:,3) < 60; %strong red compared to G or B ??
red_count = red_count + nnz(meets_red_threshold);
end
avg_count = red_count / num_files;
avg_counts(fold_idx) = avg_count;
end
plot(folder_times, avg_counts)
Gee Cheng Mun
on 12 Jan 2016
Edited: Gee Cheng Mun
on 12 Jan 2016
Walter Roberson
on 12 Jan 2016
Are they equal intervals in seconds? Does the folder name include the time in it somewhere? Do the file names of the images include the time in them somewhere? Is there a text file or xls file that has the times recorded?
Gee Cheng Mun
on 12 Jan 2016
Edited: Gee Cheng Mun
on 12 Jan 2016
Walter Roberson
on 12 Jan 2016
In the code I give above, replace
folder_times(fold_idx) = ... you didn't say how you know the time
with
timestr = regexprep( folder_info(fold_idx).name, {'^[:]+:\s+', '\s+-\s+\d+$'}, {'', ''});
folder_times(fold_idx) = str2double(timestr);
Categories
Find more on Convert Image Type 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!