function centerGPos = cenP(I ) %cenP finds the core of the PSF % [row, col] = find(I > 0); minRow = min(row); maxRow = max(row); minCol = min(col); maxCol = max(col); pos(:, :, 1) = repmat((minRow:maxRow)', [1, maxCol - minCol + 1]); pos(:, :, 2) = repmat((minCol:maxCol), [maxRow - minRow + 1, 1]); centerGPos = [sum(sum(pos(:, :, 1).*double(I(minRow:maxRow, minCol:maxCol))))/sum(sum(double(I(minRow:maxRow, minCol:maxCol)))), ... sum(sum(pos(:, :, 2).*double(I(minRow:maxRow, minCol:maxCol))))/sum(sum(double(I(minRow:maxRow, minCol:maxCol))))]; centerGPos = int16(centerGPos); end