Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to compress DICOM image to raw file format?

How to compress DICOM image to raw file format?

Scheduled Pinned Locked Moved C / C++ / MFC
comalgorithmsdata-structureshelptutorial
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 1990498
    wrote on last edited by
    #1

    1. Translate DICOM format to raw format: To save image file into a binary file format as a 1 dimensional array. 2. Compression- To use Run-Length Coding (RLC) compression algorithm to compress the information in the raw format file. INclude a header: Row & Coloumn size. 3. De-compression- Open file to display the image file. Basically it is to translate a DICOM format to raw format and save it as a binary file format. Using RLC to compress the information in the raw format file so that the image can be view in future when I open the binary file format. If anyone is able to help please drop me a mail asap to ulusai@yahoo.com.sg. Thank you.

    C 1 Reply Last reply
    0
    • U User 1990498

      1. Translate DICOM format to raw format: To save image file into a binary file format as a 1 dimensional array. 2. Compression- To use Run-Length Coding (RLC) compression algorithm to compress the information in the raw format file. INclude a header: Row & Coloumn size. 3. De-compression- Open file to display the image file. Basically it is to translate a DICOM format to raw format and save it as a binary file format. Using RLC to compress the information in the raw format file so that the image can be view in future when I open the binary file format. If anyone is able to help please drop me a mail asap to ulusai@yahoo.com.sg. Thank you.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You must have an external library to be reading a DICOM image already, what access does it give you to the image portion of the DICOM file ? Do you need to compress the layers into a single image ? Do 'raw format files' use RLC ? Surely that's not RAW then ? Or are you responsible for compression/decompression ? This looks a lot like homework to me. Define a file format, export DICOM to it, use compression and write a viewer. Where's the real world use for that ? Christian Graus - Microsoft MVP - C++

      U 1 Reply Last reply
      0
      • C Christian Graus

        You must have an external library to be reading a DICOM image already, what access does it give you to the image portion of the DICOM file ? Do you need to compress the layers into a single image ? Do 'raw format files' use RLC ? Surely that's not RAW then ? Or are you responsible for compression/decompression ? This looks a lot like homework to me. Define a file format, export DICOM to it, use compression and write a viewer. Where's the real world use for that ? Christian Graus - Microsoft MVP - C++

        U Offline
        U Offline
        User 1990498
        wrote on last edited by
        #3

        Hi, I am supposed to do compression to store the data and decompress the file for viewing. Do you have any idea how to do? I am supposed to open up an image of 256x256 and display the pixel values before storing them.

        C 1 Reply Last reply
        0
        • U User 1990498

          Hi, I am supposed to do compression to store the data and decompress the file for viewing. Do you have any idea how to do? I am supposed to open up an image of 256x256 and display the pixel values before storing them.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          OK, so you're basically reiterating the question without responding to my comments ? I suggest you review your course notes, search the web if need be, and write some code. If you're still stuck, by all means, ask specific questions, but no-one is going to do your homework for you. Christian Graus - Microsoft MVP - C++

          U 1 Reply Last reply
          0
          • C Christian Graus

            OK, so you're basically reiterating the question without responding to my comments ? I suggest you review your course notes, search the web if need be, and write some code. If you're still stuck, by all means, ask specific questions, but no-one is going to do your homework for you. Christian Graus - Microsoft MVP - C++

            U Offline
            U Offline
            User 1990498
            wrote on last edited by
            #5

            Ok, so how do I write a program to display the pixel values in the variable "image256[n]"? The values are stored in "image256[n]" but I don't know how to write a program to display them. Can you help?

            C 1 Reply Last reply
            0
            • U User 1990498

              Ok, so how do I write a program to display the pixel values in the variable "image256[n]"? The values are stored in "image256[n]" but I don't know how to write a program to display them. Can you help?

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              I take it image256 is a BYTE* or unsigned char * ( they are the same thing ) ? The easiest way to get direct access to the contents of a bitmap as a BYTE * is to create a DIBSECTION, ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_233i.asp[^] ) which will give you a HBITMAP you can pass to BitBlt or StretchBlt, and a pointer to the image bytes. This code: BITMAP bitmap; if (::GetObject(bm, sizeof(BITMAP), &bitmap)) { hdr.AddImage(new CImage(bitmap, isGrey)); } will fill a BITMAP structure with, among other things, the width, height and width in bytes of an image. To get to specific pixel value, you index your array by x*3 ( assuming a 24 bit image, 4 for a 32 bit image, and < 24 bits it just won't work ) + y * bm.WidthBytes. Then you have three bytes to read, they are the blue, green and red values. So, if you create a DIBSECTION that is the same size as your image, then you can step through and use memcpy to copy the data in, one row at a time. Bitmaps are padded to be word aligned, which is why you have the WidthBytes variable, it can be more than width*3. Your data may not be the same, otherwise I'd say just copy the whole lot in at once. Hopefully that points you in the right direction. So your library is flattening the DICOM image and giving it to you as a BYTE * then ? Christian Graus - Microsoft MVP - C++

              U 1 Reply Last reply
              0
              • C Christian Graus

                I take it image256 is a BYTE* or unsigned char * ( they are the same thing ) ? The easiest way to get direct access to the contents of a bitmap as a BYTE * is to create a DIBSECTION, ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_233i.asp[^] ) which will give you a HBITMAP you can pass to BitBlt or StretchBlt, and a pointer to the image bytes. This code: BITMAP bitmap; if (::GetObject(bm, sizeof(BITMAP), &bitmap)) { hdr.AddImage(new CImage(bitmap, isGrey)); } will fill a BITMAP structure with, among other things, the width, height and width in bytes of an image. To get to specific pixel value, you index your array by x*3 ( assuming a 24 bit image, 4 for a 32 bit image, and < 24 bits it just won't work ) + y * bm.WidthBytes. Then you have three bytes to read, they are the blue, green and red values. So, if you create a DIBSECTION that is the same size as your image, then you can step through and use memcpy to copy the data in, one row at a time. Bitmaps are padded to be word aligned, which is why you have the WidthBytes variable, it can be more than width*3. Your data may not be the same, otherwise I'd say just copy the whole lot in at once. Hopefully that points you in the right direction. So your library is flattening the DICOM image and giving it to you as a BYTE * then ? Christian Graus - Microsoft MVP - C++

                U Offline
                U Offline
                User 1990498
                wrote on last edited by
                #7

                This is how the program looks like. I need to write in that part of the program to display the black and white pixels when I run the program. I think this is where the pixels are stored. Please advise. Thank you. void CMediVisionView::ReDraw() { int row, col; int p, q, n; int cx_position[6], cy_position[6]; unsigned int data; BITMAPINFOHEADER infoHeader; infoHeader.biSize = sizeof(BITMAPINFOHEADER); infoHeader.biWidth = n_cols; infoHeader.biHeight = n_rows; infoHeader.biPlanes=1; infoHeader.biBitCount= 24; infoHeader.biCompression=0; infoHeader.biSizeImage=0; infoHeader.biXPelsPerMeter=0; infoHeader.biYPelsPerMeter=0; infoHeader.biClrUsed=0; infoHeader.biClrImportant=0; int xSize=::GetSystemMetrics(SM_CXSCREEN)-80; int ySize=::GetSystemMetrics(SM_CYSCREEN); CClientDC ClientDC(this); // Draw the Frame Lines first FrameLines(&ClientDC); if (n_rows== 256 && multiple_open) { if(image_no == 1) { cx_position[1] = posx512-4; cy_position[1] = posy512; } else if(image_no == 2) { cx_position[1] = posx512-4; cy_position[1] = posy512; cx_position[2] = posx512-4 + 256 + 3; cy_position[2] = posy512; } else if(image_no == 3) { cx_position[1] = posx512-4; cy_position[1] = posy512; cx_position[2] = posx512-4 + 256 + 3; cy_position[2] = posy512; cx_position[3] = posx512-4; cy_position[3] = posy512 + 256 + 3; } else if(image_no == 4) { cx_position[1] = posx512-4; cy_position[1] = posy512; cx_position[2] = posx512-4 + 256 + 3; cy_position[2] = posy512; cx_position[3] = posx512-4; cy_position[3] = posy512 + 256 + 3; cx_position[4] = posx512-4 + 256 + 3; cy_position[4] = posy512 + 256 + 3; } for(int s=1;s<=image_no;s++) { n = 0; for(int p=0;p

                C 1 Reply Last reply
                0
                • U User 1990498

                  This is how the program looks like. I need to write in that part of the program to display the black and white pixels when I run the program. I think this is where the pixels are stored. Please advise. Thank you. void CMediVisionView::ReDraw() { int row, col; int p, q, n; int cx_position[6], cy_position[6]; unsigned int data; BITMAPINFOHEADER infoHeader; infoHeader.biSize = sizeof(BITMAPINFOHEADER); infoHeader.biWidth = n_cols; infoHeader.biHeight = n_rows; infoHeader.biPlanes=1; infoHeader.biBitCount= 24; infoHeader.biCompression=0; infoHeader.biSizeImage=0; infoHeader.biXPelsPerMeter=0; infoHeader.biYPelsPerMeter=0; infoHeader.biClrUsed=0; infoHeader.biClrImportant=0; int xSize=::GetSystemMetrics(SM_CXSCREEN)-80; int ySize=::GetSystemMetrics(SM_CYSCREEN); CClientDC ClientDC(this); // Draw the Frame Lines first FrameLines(&ClientDC); if (n_rows== 256 && multiple_open) { if(image_no == 1) { cx_position[1] = posx512-4; cy_position[1] = posy512; } else if(image_no == 2) { cx_position[1] = posx512-4; cy_position[1] = posy512; cx_position[2] = posx512-4 + 256 + 3; cy_position[2] = posy512; } else if(image_no == 3) { cx_position[1] = posx512-4; cy_position[1] = posy512; cx_position[2] = posx512-4 + 256 + 3; cy_position[2] = posy512; cx_position[3] = posx512-4; cy_position[3] = posy512 + 256 + 3; } else if(image_no == 4) { cx_position[1] = posx512-4; cy_position[1] = posy512; cx_position[2] = posx512-4 + 256 + 3; cy_position[2] = posy512; cx_position[3] = posx512-4; cy_position[3] = posy512 + 256 + 3; cx_position[4] = posx512-4 + 256 + 3; cy_position[4] = posy512 + 256 + 3; } for(int s=1;s<=image_no;s++) { n = 0; for(int p=0;p

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  sclh wrote: StretchDIBits This means you're using a DIB - this function is what draws it. This code is ugly, it was obviously written by a C programmer who never learned C++ properly. sclh wrote: for(int s=1;s<=image_no;s++) { n = 0; for(int p=0;p for(int q=0;q data = image[s][n]; if (data <= 0) { argb256Pixels[p][q] = (unsigned int)(0 | 0 | 0 | 0); } else { argb256Pixels[p][q] = (unsigned int)(data<<24 | data<<16 | data<<8 | data); } n++; } } This code ( which has been mangled because you didn't check 'Do not treat <'s as HTML tags') is copying the pixel values. sclh wrote: argbPixelsPtr = (unsigned char *) argb256Pixels; rgbPixelsPtr = (unsigned char *) rgb256Pixels; for (row=0; row for(col=0; col *rgbPixelsPtr++ = *argbPixelsPtr++; *rgbPixelsPtr++ = *argbPixelsPtr++; *rgbPixelsPtr++ = *argbPixelsPtr++; argbPixelsPtr++; } } This bit of code is copying from one image to another, one byte at a time. It's going from a 24 bit image to a 32 bit image. Goodness knows why. Really, it seems to me like you have no idea what's happening here. Do your fellow students share your dismay ? If so, complain to the school that your teacher is no good. Assuming he wrote this code, he's definately not a person to be teaching C++. Christian Graus - Microsoft MVP - C++

                  U 1 Reply Last reply
                  0
                  • C Christian Graus

                    sclh wrote: StretchDIBits This means you're using a DIB - this function is what draws it. This code is ugly, it was obviously written by a C programmer who never learned C++ properly. sclh wrote: for(int s=1;s<=image_no;s++) { n = 0; for(int p=0;p for(int q=0;q data = image[s][n]; if (data <= 0) { argb256Pixels[p][q] = (unsigned int)(0 | 0 | 0 | 0); } else { argb256Pixels[p][q] = (unsigned int)(data<<24 | data<<16 | data<<8 | data); } n++; } } This code ( which has been mangled because you didn't check 'Do not treat <'s as HTML tags') is copying the pixel values. sclh wrote: argbPixelsPtr = (unsigned char *) argb256Pixels; rgbPixelsPtr = (unsigned char *) rgb256Pixels; for (row=0; row for(col=0; col *rgbPixelsPtr++ = *argbPixelsPtr++; *rgbPixelsPtr++ = *argbPixelsPtr++; *rgbPixelsPtr++ = *argbPixelsPtr++; argbPixelsPtr++; } } This bit of code is copying from one image to another, one byte at a time. It's going from a 24 bit image to a 32 bit image. Goodness knows why. Really, it seems to me like you have no idea what's happening here. Do your fellow students share your dismay ? If so, complain to the school that your teacher is no good. Assuming he wrote this code, he's definately not a person to be teaching C++. Christian Graus - Microsoft MVP - C++

                    U Offline
                    U Offline
                    User 1990498
                    wrote on last edited by
                    #9

                    Hi, does that means the whole program should be using DIB instead of MFC C++? The part on converting DICOM to raw format?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups