faceFile = [1:11]; fileBase = 'face%d.tiff'; targetH = 160*2; targetW = 120*2; allF = zeros(length(faceFile), targetH, targetW, 3); %load all the imges for idxF=1:length(faceFile) refF = faceFile(idxF); fName = sprintf(fileBase, refF); fprintf('Load %d ...\n', idxF); [X,map] = imread(fName); allF(idxF, :, :, :) = imresize(X, [targetH targetW]); end; % average the images combinedMean = zeros(targetH, targetW, 3); combinedMed = zeros(targetH, targetW, 3); combinedMin = zeros(targetH, targetW, 3); combinedMax = zeros(targetH, targetW, 3); if (1) for idxP = 1:length(combinedF(:)) combinedMean(idxP) = median(allF(:,idxP)); combinedMed(idxP) = mean(allF(:,idxP)); combinedMin(idxP) = min(allF(:,idxP)); combinedMax(idxP) = max(allF(:,idxP)); end; combinedMean = uint8(combinedMean); combinedMed = uint8(combinedMed); combinedMin = uint8(combinedMin); combinedMax = uint8(combinedMax); end; combinedRand = combinedMax; if (1) chunkSize = 2; rowWidth = ceil(targetW/chunkSize); colHeight = ceil(targetH/chunkSize); chunkNum = ceil(rowWidth*colHeight); chunkOrder = randperm(chunkNum); chunkLayer = 1+floor(rand(length(chunkOrder), 4)*length(faceFile)); for chunkRef=1:chunkNum/4 chunkIdx = chunkOrder(chunkRef); idxC = mod(chunkIdx-1, colHeight); cCol = round((idxC*chunkSize) + 1); cRow = round((((chunkIdx-idxC-1)/colHeight)*chunkSize) + 1); cRowEnd = min(targetW, cRow+chunkSize); cColEnd = min(targetH, cCol+chunkSize); for idxC=1:3 combinedRand(cCol:cColEnd, cRow:cRowEnd, idxC) = ... max(allF(chunkLayer(chunkRef,:), cCol:cColEnd,cRow:cRowEnd,idxC)); end; end; end; combinedRand = uint8(combinedRand); % show the images figure(1); subplot(1,5,1), imshow(combinedMean); title('mean'); subplot(1,5,2), imshow(combinedMed); title('median'); subplot(1,5,3), imshow(combinedMin); title('min'); subplot(1,5,4), imshow(combinedMax); title('max'); subplot(1,5,5), imshow(combinedRand); title('rand'); figure(2); imshow(combinedMax); print('-dpng', 'finalface.png');