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;endfilePattern = fullfile(myFolder, '*.png'); theFiles = dir(filePattern);numberOfImages=length(theFiles);red_counts = zeros(1, numberOfImages);redCount=0;for k=1:numberOfImagesfullFileName = 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;endplot(red_counts, numberOfImages, '-r*');set(gca, 'xTickLabel', 1:1:numberOfImages);ylabel('Red pixel count');xlabel('Number of images');
Best Answer