필터 지우기
필터 지우기

Undefined function or variable 'totalredCount'.

조회 수: 1 (최근 30일)
Gee Cheng Mun
Gee Cheng Mun 2016년 1월 11일
편집: Stephen23 2016년 1월 11일
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일
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개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by