フィルターのクリア

Graph plotting of number of red pixels vs number of images?

1 回表示 (過去 30 日間)
Gee Cheng Mun
Gee Cheng Mun 2016 年 1 月 13 日
コメント済み: Gee Cheng Mun 2016 年 1 月 13 日
I would like to count the number of red pixels for every image in this folder. Next, plot the graph of no. of red pixels for each image vs the no. of images? How can this be done?
[Merged from duplicate question]
I would like to calculate the red pixel count for every image in this folder and then plot a graph of red pixel count vs the number of images. The red pixel count must correspond to the image no. This is my code.
%for loop
clc;
clear;
close all;
fontSize=10;
myFolder='G:\FYP2\Time Frames\Frame 24';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.png');
theFiles = dir(filePattern);
numberOfImages=length(theFiles);
red_counts = zeros(1, numberOfImages);
redCount=0;
for k=1:numberOfImages
fullFileName = fullfile(myFolder, theFiles(k).name);
thisImage=double(imread(fullFileName));
[rows, columns, numberOfColorBands] = size(thisImage);
redBand=thisImage(:,:,1);
%THRESHOLD LEVELS
redThresholdLow=215;
redThresholdHigh=255;
redMask=(redBand>=redThresholdLow) & (redBand<=redThresholdHigh);
%Count pixels
redCount=sum(redMask(:)>0);
red_counts(k)=redCount;
end
plot(red_counts, numberOfImages, '-r*');
set(gca, 'xTickLabel', 1:1:numberOfImages);
ylabel('Red pixel count');
xlabel('Number of images');
  2 件のコメント
Gee Cheng Mun
Gee Cheng Mun 2016 年 1 月 13 日
I know to calculate the red pixels for the images. However, how can I display it as a graph of no. of red pixels vs no. of images?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 13 日
Everything is written for you in http://uk.mathworks.com/matlabcentral/answers/263333-how-to-plot-an-intensity-graph#comment_334704 (you will have to view old comments there to see the code again.)
The key line is
meets_red_threshold = thisimage(:,:,1) > 180 & thisimage(:,:,2) < 60 & thisimage(:,:,3) < 60; %strong red compared to G or B ??
You need to alter this line to match your definition of what a "red pixel" is. Is a pixel "red" if it has any non-zero R component and the G and B components are 0? Visually you would find it difficult to distinguish such a pixel from black. If you plot [0.8 0.01 0.01] on the same line graph as [1 0 0] you are going to have trouble telling the two apart. So you need to define exactly what "red" means to you, as there is no scientific definition of what is "red" and what is not.
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 1 月 13 日
Then see the code before that in the earlier comment http://uk.mathworks.com/matlabcentral/answers/263333-how-to-plot-an-intensity-graph#comment_334697 and just replace the assignment of
t(K) = (K-1)/24;
with
t(K) = K;
Gee Cheng Mun
Gee Cheng Mun 2016 年 1 月 13 日
Thank you so much!:)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by