Undefined function or variable 'totalredCount'.
Afficher commentaires plus anciens
I am trying to obtain average values using the code below.
%for loop
clc;
clear;
close all;
fontSize=10;
myFolder='G:\FYP2\Time Frames\Frame 15';
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);
for k=1:numberOfImages
fullFileName = fullfile(myFolder, theFiles(k).name);
thisImage=double(imread(fullFileName));
[rows, columns, numberOfColorBands] = size(thisImage);
%EXTRACT OUT THE COLOR BANDS FROM THE ORIGINAL IMAGE
redBand=thisImage(:,:,1);
greenBand=thisImage(:,:,2);
blueBand=thisImage(:,:,3);
%THRESHOLD LEVELS
redThresholdLow=215;
redThresholdHigh=255;
greenThresholdLow=220;
greenThresholdHigh=255;
blueThresholdLow=240;
blueThresholdHigh=255;
redMask=(redBand>=redThresholdLow) & (redBand<=redThresholdHigh);
greenMask=(greenBand>=greenThresholdLow) & (greenBand<=greenThresholdHigh);
blueMask=(blueBand>=blueThresholdLow) & (blueBand<=blueThresholdHigh);
yellowMask = uint8(redMask & greenMask);
turMask = uint8(blueMask & greenMask);
%Count pixels
redCount=sum(redMask(:)>0);
greenCount=sum(greenMask(:)>0);
yellowCount=sum(yellowMask(:)>0);
turCount=sum(turMask(:)>0);
%Compute area fraction
totalArea=rows * columns;
redAreaFraction=redCount/totalArea;
greenAreaFraction=greenCount/totalArea;
yellowAreaFraction=yellowCount/totalArea;
turAreaFraction=turCount/totalArea;
%Compute area percentage
percentRED=100.0 * redAreaFraction;
percentGREEN=100.0 * greenAreaFraction;
percentYELLOW=100.0 * yellowAreaFraction;
percentTUR=100.0 * yellowAreaFraction;
if k==1
redCount=totalredCount;
greenCount=totalgreenCount;
yellowCount=totalyellowCount;
turCount=totalturCount;
redAreaFraction=totalredAF;
greenAreaFraction=totalgreenAF;
yellowAreaFraction=totalyellowAF;
turAreaFraction=totalturAF;
percentRED=totalpercentRED;
percentGREEN=totalpercentGREEN;
percentYELLOW=totalpercentYELLOW;
percentTUR=totalpercentTUR;
else
redCount=redCount+totalredCount;
greenCount=greenCount+totalgreenCount;
yellowCount=yellowCount+totalyellowCount;
turCount=turCount+totalturCount;
redAreaFraction=redAreaFraction+totalredAF;
greenAreaFraction=greenAreaFraction+totalgreenAF;
yellowAreaFraction=yellowAreaFraction+totalyellowAF;
turAreaFraction=turAreaFraction+totalturAF;
percentRED=percentRED+totalpercentRED;
percentGREEN=percentGREEN+totalpercentGREEN;
percentYELLOW=percentYELLOW+totalpercentYELLOW;
percentTUR=percentTUR+totalpercentTUR;
end
end
%Average values for 1 time frame
ARC=redCount/numberOfImages;
AGC=greenCount/numberOfImages;
AYC=yellowCount/numberOfImages;
ATC=turCount/numberOfImages;
ARAF=redAreaFraction/numberOfImages;
AGAF=greenAreaFraction/numberOfImages;
AYAF=yellowAreaFraction/numberOfImages;
ATAF=turAreaFraction/numberOfImages;
APF=percentRED/numberOfImages;
APG=percentGREEN/numberOfImages;
APY=percentYELLOW/numberOfImages;
APT=percentTUR/numberOfImages;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!