2

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

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
로다현
  • 125
  • 1
  • 12
  • 1
    My plan is now to get the midpoint of the whole pixel or After designating a rectangle programmatically, I am thinking of increasing the scale value based on the midpoint of the specified rectangle. But I can't figure out how to implement it in code... – 로다현 Dec 16 '21 at 08:52
  • 3
    Do you have any reason to believe the images *should* match exactly? If the images are taken with different machines, or at different times, it is unlikely that the person is positioned exactly the same. – JonasH Dec 16 '21 at 08:55
  • 1
    @JonasH I pull these pictures from the same machine Actually the location of the photo Location There may be a difference of mm, but such an error is acceptable – 로다현 Dec 16 '21 at 08:57
  • 2
    Am I the only person who can see just a single image in the post? The question talks about multiple images; would it not be sensible to show us all the images (the inputs as well as the output)? – Caius Jard Dec 16 '21 at 09:08
  • @CaiusJard I edited the post, can you see it again? – 로다현 Dec 16 '21 at 09:52
  • 1
    Are you sure the images have the same field of view? I.e. does voxel (0,0) indeed match with voxel (0,0) and voxel (167,167) with (voxel 511,511)? You should check the corresponding DICOM data if they do. For example, a typical PET voxel is 4x4 mm^2, resulting in a total FoV of 672x672mm, a CT voxel can be 0.76x0.76 mm^2, resulting in a total FoV of 389x389mm. You should match based on the voxel sizes, not based on image resolution. – nucleaR Dec 16 '21 at 10:02
  • @nucleaR I don't quite understand the concept of voxel, but I know that concept appears as a mm value at the location of the dicom tag. Such an error is within the allowable range. The problem now is that not all dicom image fusions are accurate. – 로다현 Dec 16 '21 at 10:12
  • 1
    A voxel is the pixel representation of a 3d space from which a pixel was sampled during scanning. But that's not really important. What IS important is to know what the real/absolute dimensions of both images are (in mm). Can you provide us with those dimensions? It is very likely that they are not the same, resulting in the problem you now present. – nucleaR Dec 16 '21 at 10:18
  • @nucleaR The difference between these two figures is 0.2mm. – 로다현 Dec 16 '21 at 10:23
  • I've a quick question; if you use a paint program to resize and overlay original image 1 on original image 2, do they align exactly as you expect or are they in error by the same amount as your code's output. If they align then the code is generating a misaligned image. If they do not align then the code may be correct but some adjustment is required because the images aren't naturally aligned (I would test this but only got a cellphone atm) – Caius Jard Dec 16 '21 at 10:49
  • 1
    I did that and the result is exactly the same as the OP got from his code. I'm fairly certain the FoV is not the same, but the OP claims it is. So it's not the code, and the OP says it's not due to a difference in pixel size, then there is no way to answer the question. – nucleaR Dec 16 '21 at 14:42
  • @nucleaR I uploaded the slice location to the post. The dicom file contains personal information, so please understand that the file itself cannot be uploaded. – 로다현 Dec 17 '21 at 00:34
  • @nucleaR At first, I thought that the value could be calculated within the error range with the slice location. However, since Daicom cut 3d into 2d, I didn't think that the top left (0,0) itself would be different. I plan to redo the origin designation with that information. thankyou – 로다현 Dec 17 '21 at 01:19
  • @nucleaR thankyou Now I understand you correctly. thank you – 로다현 Dec 20 '21 at 07:50

1 Answers1

0

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.

로다현
  • 125
  • 1
  • 12