Undefined function or variable 'totalredCount'.

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;

 採用された回答

Image Analyst
Image Analyst 2016 年 1 月 11 日

0 投票

I don't know what that variable is supposed to represent, but you never assign any value to it before you try to use it in the line of code that throws the error. It's not defined yet so that's what the error is telling you.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2016 年 1 月 11 日

編集済み:

2016 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by