MATLAB: How to shift object to the center of the image

digital image processingimageimage processingImage Processing Toolboximage segmentation

I have xray images where the chest is not in the center of the image. For example, as shown in the following two figures. I want to shift the person in the center of the image. I need to do it automatically, i.e., the program should identify the current location of the chest region in the image and if the chest is not in the center of the image then shift it to the center. Any help is highly appreciated.
Thanks

Best Answer

This has two parts:
  1. identifying where the center of the object of interest is
  2. arranging for it to be placed at the center of a new image
You will need to do some kind of feature matching to figure out where the center of the chest is, I guess. There is no Mathworks-provided function that can automatically identify where the center of a chest is on an x-ray.
To arrange for a pixel to be placed at the center of a new image, calculate the minimum of the distance to the two edges, and crop at center minus distance to center plus distance.
Before doing any of this you probably want to eliminate background by cropping.