Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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');

Risposta accettata

Walter Roberson
Walter Roberson il 13 Gen 2016
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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by