function alignedImage = autoAlign(image, powerOfTwo)

  mostMutualInfoSoFar = 0;
  bestRowShiftSoFar = -15;
  bestColShiftSoFar = -15;
  for rowShift = -15 : 15
    for colShift = -15 : 15
      shiftedGreen = circshift(image(:,:,2), [rowShift, colShift]);
      jointDistribution = jointDistFromImages(image(:,:,1), shiftedGreen, powerOfTwo);
      mutualInfo = mutInfo(jointDistribution);
      if(mutualInfo > mostMutualInfoSoFar)
        mostMutualInfoSoFar = mutualInfo;
        bestRowShiftSoFar = rowShift;
        bestColShiftSoFar = colShift;
      end
    end
  end

  image(:, :, 2) = circshift(image(:, :, 2), [bestRowShiftSoFar, bestColShiftSoFar]);

  
  mostMutualInfoSoFar = 0;
  bestRowShiftSoFar = -15;
  bestColShiftSoFar = -15;
  for rowShift = -15 : 15
    for colShift = -15 : 15
      shiftedBlue = circshift(image(:,:,3), [rowShift, colShift]);
      jointDistribution = jointDistFromImages(image(:,:,1), shiftedBlue, powerOfTwo);
      mutualInfo = mutInfo(jointDistribution);
      if(mutualInfo > mostMutualInfoSoFar)
        mostMutualInfoSoFar = mutualInfo;
        bestRowShiftSoFar = rowShift;
        bestColShiftSoFar = colShift;
      end
    end
  end

  image(:, :, 3) = circshift(image(:, :, 3), [bestRowShiftSoFar, bestColShiftSoFar]);

  alignedImage = image;

end
