Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ error, falseNeg, falsePos ] = UseBoostedFeatures
- Faces = ReadBmps('G:\Download\project2\Face16');
- faceSize = size(Faces, 1);
- Nonfaces = ReadBmps('G:\Download\project2\Nonface16');
- nonFaceSize = size(Nonfaces, 1);
- Results = zeros(200, 3);
- %test start here
- for w=2:200
- resultFromAdaboost = zeros(8, w); %change this for how many boosted youre testing
- resultFromAdaboost = dlmread(strcat('selectedFeaturesBoosted', num2str(w), '.txt'));
- halfSumTotalWeight = 0;
- for y=1:size(resultFromAdaboost, 2);
- beta = resultFromAdaboost(8, y) / (1 - resultFromAdaboost(8, y));
- alpha = log10(1/beta);
- halfSumTotalWeight = halfSumTotalWeight + alpha;
- end
- halfSumTotalWeight = .5 * halfSumTotalWeight;
- falseNeg = 0;
- falsePos = 0;
- totalError = 0;
- for faceImage=1:faceSize
- accumulation = 0;
- for l=1:size(resultFromAdaboost, 2);
- classification = 0;
- i = resultFromAdaboost(1, l);
- j = resultFromAdaboost(2, l);
- rows = resultFromAdaboost(3, l);
- columns = resultFromAdaboost(4, l);
- threshold = resultFromAdaboost(5, l);
- type = resultFromAdaboost(7, l);
- if(type == 1)
- upperLeft = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j, i+(rows/2)-1, j+(columns/2)-1);
- upperRight = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j+(columns/2), i+(rows/2)-1, j+(columns)-1);
- lowerRight = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i+(rows/2), j+(columns/2), i+(rows)-1, j+(columns)-1);
- lowerLeft = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i+(rows/2), j, i+(rows)-1, j+(columns/2)-1);
- Result = upperRight + lowerLeft - upperLeft - lowerRight;
- if Result >= threshold %correct
- classification = 1;
- else
- classification = 0;
- end
- elseif(type == 2)
- top = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j, i+(rows/2)-1, j+(columns)-1);
- bottom = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i+(rows/2), j, i+(rows)-1, j+(columns)-1);
- Result = top - bottom;
- if Result >= threshold %correct
- classification = 1;
- else
- classification = 0;
- end
- elseif(type == 3)
- left = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j, i+(rows)-1, j+(columns/2)-1);
- right = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j+(columns/2), i+(rows)-1, j+(columns)-1);
- Result = right - left;
- if Result >= threshold %correct
- classification = 1;
- else
- classification = 0;
- end
- elseif(type == 4)
- leftThird = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j, i+(rows)-1, j+(columns/3)-1);
- middleThird = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j+(columns/3), i+(rows)-1, j+(2*columns/3)-1);
- rightThird = IntegralSum(reshape(Faces(faceImage,:,:), 16, 16), i, j+(2*columns/3), i+(rows)-1, j+(columns)-1);
- Result = middleThird - leftThird - rightThird;
- if Result >= threshold %correct
- classification = 1;
- else
- classification = 0;
- end
- end
- if(classification == 1)
- beta = resultFromAdaboost(8, l) / (1 - resultFromAdaboost(8, l));
- alpha = log10(1/beta);
- accumulation = accumulation + alpha;
- end
- end
- if accumulation >= halfSumTotalWeight %correct classification
- else
- falseNeg = falseNeg + 1;
- totalError = totalError + 1;
- end
- end
- for nonFaceImage=1:nonFaceSize
- accumulation = 0;
- for l=1:size(resultFromAdaboost, 2);
- classification = 0;
- i = resultFromAdaboost(1, l);
- j = resultFromAdaboost(2, l);
- rows = resultFromAdaboost(3, l);
- columns = resultFromAdaboost(4, l);
- threshold = resultFromAdaboost(5, l);
- type = resultFromAdaboost(7, l);
- if(type == 1)
- upperLeft = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j, i+(rows/2)-1, j+(columns/2)-1);
- upperRight = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j+(columns/2), i+(rows/2)-1, j+(columns)-1);
- lowerRight = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i+(rows/2), j+(columns/2), i+(rows)-1, j+(columns)-1);
- lowerLeft = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i+(rows/2), j, i+(rows)-1, j+(columns/2)-1);
- Result = upperRight + lowerLeft - upperLeft - lowerRight;
- if Result >= threshold %incorrect
- classification = 1;
- else
- classification = 0;
- end
- elseif(type == 2)
- top = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j, i+(rows/2)-1, j+(columns)-1);
- bottom = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i+(rows/2), j, i+(rows)-1, j+(columns)-1);
- Result = top - bottom;
- if Result >= threshold %incorrect
- classification = 1;
- else
- classification = 0;
- end
- elseif(type == 3)
- left = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j, i+(rows)-1, j+(columns/2)-1);
- right = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j+(columns/2), i+(rows)-1, j+(columns)-1);
- Result = right - left;
- if Result >= threshold %incorrect for non face
- classification = 1;
- else
- classification = 0;
- end
- elseif(type == 4)
- leftThird = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j, i+(rows)-1, j+(columns/3)-1);
- middleThird = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j+(columns/3), i+(rows)-1, j+(2*columns/3)-1);
- rightThird = IntegralSum(reshape(Nonfaces(nonFaceImage,:,:), 16, 16), i, j+(2*columns/3), i+(rows)-1, j+(columns)-1);
- Result = middleThird - leftThird - rightThird;
- if Result >= threshold %incorrect
- classification = 1;
- else
- classification = 0;
- end
- end
- if(classification == 1)
- beta = resultFromAdaboost(8, l) / (1 - resultFromAdaboost(8, l));
- alpha = log10(1/beta);
- accumulation = accumulation + alpha;
- end
- end
- if accumulation >= halfSumTotalWeight
- falsePos = falsePos + 1;
- totalError = totalError + 1;
- else
- end
- end
- error = totalError / 15175;
- sprintf('%f %f %f', error, falseNeg, falsePos)
- Results(w, 1) = error;
- Results(w, 2) = falseNeg;
- Results(w, 3) = falsePos;
- end
- dlmwrite('trainingErrors.txt', Results);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement