how to obtain Oblique cuts from 3d images Array?

101 views
Skip to first unread message

Watcher Tester

unread,
Nov 10, 2017, 2:22:56 PM11/10/17
to Fellow Oak DICOM

I'm working on a Dicom reader project using c# with Fo-Dicom , and I'm trying to obtain the axial , coronal , sagittal and oblique cuts from 3 dimensional array , the first and second dimensions of the array are for the width and the height and the third one is for the frames counter .

now I managed to obtain axial , coronal and sagittal cuts by looping through each frame in the array but with one constant dimension for each iteration , for the axial the z is the constant and for the coronal the y is constant and for the sagittal the x is constant in each iteration . here is the code to obtain axial cuts :


 public unsafe Bitmap GetImageFromPerspective(int slicePosition, Perspective perspective)
    {


        #region normal
        if (perspective == Perspective.Axial) // X-axis perspective
        {

            if (slicePosition > (_imagesMatrix.GetLength(2) - 1))
                slicePosition = (_imagesMatrix.GetLength(2) - 1);

            if (slicePosition < 0)
                slicePosition = 0;

            Bitmap bmp = new Bitmap(_height ,_width , PixelFormat.Format24bppRgb);
            BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);
            int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(bmp.PixelFormat) / 8;
            int heightInPixels = bitmapData.Height;
            int widthInBytes = bitmapData.Width * bytesPerPixel;
            byte* ptrFirstPixel = (byte*)bitmapData.Scan0;


            double lowestValue = _windowCenter - (_windowWidth / 2);
            double highestValue = _windowCenter + (_windowWidth / 2);


            Parallel.For(0, _imagesMatrix.GetLength(1) , column =>
            {
                byte* currentLine = ptrFirstPixel + (column * bitmapData.Stride);
                for (int row = 0; row < _imagesMatrix.GetLength(0); row++)
                {

                    double val = (_imagesMatrix[row, column, slicePosition] / ((highestValue - lowestValue)/256) );

                    if (val < 0) val = 0;
                    if (val > 255) val = 255;
                    currentLine[row * 3] = (byte)val;
                    currentLine[row * 3 + 1] = (byte)val;
                    currentLine[row * 3 + 2] = (byte)val;
                }
            });

            bmp.UnlockBits(bitmapData);
            return bmp;

        }


and for coronal the only thing changed (beside the bitmap width/height) :
      
double val = (double)(_imagesMatrix[row, slicePosition, column] / ((highestValue - lowestValue) / 256));

and for sagittal :
      
double val = (double)(_imagesMatrix[slicePosition, row, column] / ((highestValue - lowestValue) / 256));


now my question is how to obtain oblique cuts from the same array and output it as a bitmap as i did for the other cuts (I know i have to deal with some angles but i don't know how ) ??

Reply all
Reply to author
Forward
0 new messages