Home > database >  How to fit two images into one image
How to fit two images into one image

Time:12-21

I am working on a project to fuse two DICOM Image by myself.

Image 1 (168x168) When the images of Image 2 (512x512) are combined, the two images do not match at all.

I don't think there's a problem with the merging script, but If you think the merging code is the problem, you can ask for it.

Image 2 (512x512)

enter image description here

Image 1 (168x168)

Image

Upsizing is finished Image 1 (168x168) => Image 1 (512x512)Image

enter image description here

fusion result

enter image description here

The red part of the picture should match the gray part.

If you look closely at the picture, you can see that the scale is slightly small and does not exactly match up, down, left and right.

Problem (I guess)

  1. When changing from 168 to 512, the decimal points are multiplied and the pixel values ​​of small points are lost.

  2. Since the 512x512 Image 1 is not fixed in the center, if I increase the scale and do not give a padding value, it will not fit.

it is resize code

public static Bitmap resizeImage(Bitmap image, int width, int height)
        {
            var destinationRect = new Rectangle(0, 0, width, height);
            var destinationImage = new Bitmap(width, height);

            destinationImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destinationImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destinationRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            return destinationImage;
        }

image 2

enter image description here enter image description here enter image description here

image 1

enter image description here enter image description here enter image description here

CodePudding user response:

thankyou for nucleaR

i make

enter image description here

  1. The ImageOrientationPatient value is the XYZ value of the cropped position
  2. PixelSpacing This is the data value of this voxel. The actual size of one pixel can be calculated from this.
  1. Before resizing the image, since the PT coordinates are larger, the corresponding pixels must be cut from the pt coordinates. How to calculate cropping this pixel is important
  2. If you cut pixels, you have to cut 168 because it will be based on 512 pixels.
Value=pixelSpacingPT* 168 - pixelSpacingCT *512  

cutPixel=Value/pixelSpacingPT;

The pixels to be cropped are now 20 pixels wide I found out that it is 20 pixels in height.

  • Related