Image processing: how do I erode on boundary and dilate inside boundary?
You will want to use the morphological closing operation, which is the erosion of the dilation of an image. This means that you first dilate the image, removing the small 'holes' in the interior of the image, and then you erode the image, shrinking the boundary. If you want the final boundary to be 'smaller' than the original boundary, simply erode more than you dilate, ensuring that you dilate enough to completely fill the interior holes first.

The idea behind this is that by removing the holes via dilation, the information about those holes is lost from the image. When you then proceed to erode the image, there are no longer interior gaps to erode away from, so it only erodes away from the outer image. Therefore, despite being opposing operations, the erosion does not simply reverse the dilation, provided the feature sizes to be removed are 'smaller' than the size of the dilation.