필터 지우기
필터 지우기

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');

채택된 답변

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 CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by