1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem obtaining the filesize correct (HELP!!)

Discussion in 'C' started by beanbean, Nov 2, 2009.

  1. beanbean

    beanbean New Member

    Joined:
    Oct 15, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi, i am a final year student doing a project using c++ language.
    • In this project, i have to perform Boolean operation and transfer bitmap to DICOM file.
    • In this program that i have attached the function on reading the DICOM file.
    • When i saved the new DICOM file after performing Boolean operation, the filesize end up 1kb less than the orginal DICOM file (incorrect!)
    • From the ReadDICOM(void), i have to comment out all fwrite statements except for header file.
    • It is to overwrite the original DICOM file.
    • Can you help me solve the problem? thanks.
    Code:
    void CLEO_MedivisionView::ReadDICOM(void)
    {
        FILE *fp;
        FILE *ft;
        errno_t err;
        char t;
        char a[5]; //Use for reading 'DICOM'
        char VR[3];
        char UID[30]; //For storing transfer syntax
        char *String;
        int i, j, k, iLength, loop; //For general use
        int ValueLength;
        float FValueField, maxpix;
        bool flag; //Flag to indicate continue reading the File Header and data
        short tag[2]; //Tags for group number and element number
        short sdata;
        short pixelval; //Variable to store raw pixel value from image file
        short SValueLength;
        short ValueField;
        long num, position;
        unsigned long LValueField;
        unsigned short ReservedField;
        unsigned long LValue; //Variable to store any long datatype
    
    //------------- Code to convert the CString m_File1 to char filename -----------------------
        const size_t StringSize = 100;
        size_t CharactersConverted = 0;
        char filename[StringSize];
        wcstombs_s(&CharactersConverted, filename, m_File1.GetLength()+1, m_File1, _TRUNCATE);
     
    // pixelmax = 256;
        ValueLength = 0;
        flag = true; //Flag for continuous reading of image data in while loop
        if ((err = fopen_s(&ft, "kp_ry.dcm", "wb+")) != 0)
        {
            printf("Cannot open binary file!");
            fclose(ft);
        }
     
        if ((err = fopen_s(&fp, filename, "rb")) != 0)
        {
            printf("Cannot open binary file!");
            fclose(fp);
        }
        else {
    //-------------------------------- Read Meta-File ------------------------------------------
            fseek(fp, 128, 0); //Skip 128 Bytes
            fseek(ft, 128, 0);
     
            fgets(a, 5, fp); //Retreive 'DICM' code
            fputs(a, ft);
     
    //------------------------------------------------------------------------------------------
            while (flag == true)   //Continue reading file when 'flag' is true
            {
                for (i=0; i<2; i++)
                {
                    fread(&tag[i], sizeof(unsigned short), 1, fp); //Ordered pair of 16-bit unsigned int
                    fwrite(&tag[i], sizeof(unsigned short), 1, ft);
    // fwrite(&tag[0], sizeof(unsigned short), 1, ft);
    // fwrite(&tag[0], sizeof(unsigned short), 1, ft);
    // fread(&tag[1], sizeof(unsigned short), 1, fp); //Ordered pair of 16-bit unsigned int
    // fwrite(&tag[1], sizeof(unsigned short), 1, ft);
                }
                if (tag[0]< 32736)  //If it is in File-Header area
                {
     
    //----------------------------- Group 2 Header information ---------------------------------
     
                    if (tag[0] == 2)   //If Tag[0]=0002 hex(Group 2)
                    {
                        strcpy(VR, " ");
                        fgets(VR,3,fp); //Read the VR first
                        fwrite(VR,sizeof(char), 2, ft);
                        if (tag[1] == 16)   //Check for Transfer Syntax ID
                        {
                            fread(&ValueLength, sizeof(unsigned short), 1, fp); //Read the ValueLength
                            fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                            fgets(UID, ValueLength+1, fp);
                            fwrite(UID, sizeof(char), ValueLength, ft);
                            TagInfodlg.SetDlgItemText(IDC_EDIT5, (CString)(UID));
                        }
                        else
                        {
                            if (strcmp(VR,"UL")==0)
                            {
                                fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                fread(&LValueField, sizeof(unsigned long), 1, fp);
                                fwrite(&LValueField, sizeof(unsigned long), 1, ft);
                            }
                            else if (strcmp(VR,"OB")==0)
                            {
                                fread(&ReservedField, sizeof(unsigned short), 1, fp);
                                fwrite(&ReservedField, sizeof(unsigned short), 1, ft);
                                fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                fread(&LValueField, sizeof(unsigned long), 1, fp);
                                fwrite(&LValueField, sizeof(unsigned long), 1, ft);
                            }
                            else if (strcmp(VR,"UI")==0)
                            {
                                fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                            }
                            else if (strcmp(VR,"SH")==0)
                            {
                                fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                            }
                            else if (strcmp(VR,"AE")==0)
                            {
                                fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                            }
                            else   // Read Implicit CS
                            {
                                num = (int)VR[0];
                                fgetc(fp);
     
                                for (loop=0; loop<num+2; loop++)
                                {
                                    t = fgetc(fp);
                                    fputc(t,ft);
                                }
                            }
                        }
                    }
    // ------------------------- Other Group Header information --------------------------------
    // --------------- For Implicit VR Little Endian : DICOM default type ----------------------
                    else
                    {
                        if (strcmp(UID,"1.2.840.10008.1.2")==0)   //Implicit VR Little Endian: Default for DICOM
                        {
                            fread(&ValueLength, sizeof(unsigned int) , 1, fp); //Read the ValueLength
                            fwrite(&ValueLength, sizeof(unsigned int) , 1, ft);
                            if (tag[0] == 0x28 && tag[1] == 0x10)  //Get Image Row size
                            {
                                fread(&sdata, sizeof(unsigned short), 1, fp);
                                fwrite(&sdata, sizeof(unsigned short), 1, ft);
                                no_of_rows = sdata;
                                TagInfodlg.SetDlgItemInt(IDC_EDIT1, sdata);
                            }
                            else if (tag[0] == 0x28 && tag[1] == 0x11)  //Get Image Col size
                            {
                                fread(&sdata, sizeof(unsigned short), 1,fp);
                                fwrite(&sdata, sizeof(unsigned short), 1, ft);
                                no_of_cols = sdata;
                                TagInfodlg.SetDlgItemInt(IDC_EDIT2, sdata);
                            }
                            else if (tag[0] == 0x28 && tag[1] == 0x30)  //Get Pixel Spacing
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                pixel_res = atof(String);
                                TagInfodlg.SetDlgItemText(IDC_EDIT13, CString(String));
                            }
     
                            else if (tag[0] == 0x18 && tag[1] == 0x50)  //Get Slice Thickness
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                slice_thickness = atof(String);
                                TagInfodlg.SetDlgItemText(IDC_EDIT3, CString(String));
                            }
                            else if (tag[0] == 0x10 && tag[1] == 0x20)  //Get Patient's ID
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                Patient_ID = String;
                                TagInfodlg.SetDlgItemText(IDC_EDIT6, CString(String));
    // TagInfodlg.SetDlgItemText(IDC_EDIT6, CString("Undisclosed"));
                            }
                            else if (tag[0] == 0x10 && tag[1] == 0x10)  //Get Patient's Name
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT4, CString(String));
    // TagInfodlg.SetDlgItemText(IDC_EDIT4, CString("Undisclosed"));
                            }
                            else if (tag[0] == 0x10 && tag[1] == 0x40)  //Get Patient's Gender
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT8, CString(String));
                            }
                            else if (tag[0] == 0x10 && tag[1] == 0x1010)  //Get Patient's Age
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT7, CString(String));
                            }
                            else if (tag[0] == 0x10 && tag[1] == 0x1030)  //Get Patient's Weight
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT14, CString(String));
                            }
                            else if (tag[0] == 0x20 && tag[1] == 0x13)  //Get Image Number
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                slice_img = CString(String);
                                TagInfodlg.SetDlgItemText(IDC_EDIT15, slice_img);
                            }
                            else if (tag[0] == 0x20 && tag[1] == 0x32)  //Get Image Position
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT11, CString(String));
                            }
                            else if (tag[0] == 0x8 && tag[1] == 0x60)  //Get Modality
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT9, CString(String));
                            }
                            else if (tag[0] == 0x8 && tag[1] == 0x70)  //Get Modality Manufacturer
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT12, CString(String));
                            }
                            else if (tag[0] == 0x8 && tag[1] == 0x8)  //Get Image Type
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                                TagInfodlg.SetDlgItemText(IDC_EDIT10, CString(String));
                            }
                            else if (tag[0] == 0x817)
                            {
                                fseek(fp, ValueLength, SEEK_CUR);
                                fseek(ft, ValueLength, SEEK_CUR);
                            }
                            else   //All other data not needed, store it as string
                            {
                                String=new char[ValueLength+1];
                                fgets(String, ValueLength+1, fp);
                                fwrite(String, sizeof(char), ValueLength, ft);
                            }
                        }
    // -------------------------- For Explicit VR Little Endian --------------------------------
                        else if (strcmp(UID,"1.2.840.10008.1.2.1")==0)
                        {
                            strcpy(VR, " ");
                            fgets(VR,3,fp); //Read VR
                            fwrite(VR, sizeof(char), 2, ft);
                            if (tag[0] == 40 && tag[1] == 16)   //Get Image Row Size
                            {
                                fread(&SValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&SValueLength, sizeof(unsigned short), 1, ft);
                                fread(&sdata, sizeof(unsigned short), 1, fp);
                                fwrite(&sdata, sizeof(unsigned short), 1, ft);
                                no_of_rows = sdata;
                                TagInfodlg.SetDlgItemInt(IDC_EDIT1, sdata);
                            }
                            else if (tag[0] == 40 && tag[1] == 17)  //Get Image Col Size
                            {
                                fread(&SValueLength, sizeof(unsigned short), 1, fp);
                                fwrite(&SValueLength, sizeof(unsigned short), 1, ft);
                                fread(&sdata, sizeof(unsigned short), 1,fp);
                                fwrite(&sdata, sizeof(unsigned short), 1, ft);
                                no_of_cols = sdata;
                                TagInfodlg.SetDlgItemInt(IDC_EDIT2, sdata);
                            }
                            else if (tag[0] == 40 && tag[1] == 263)   // Reading of maximum pixel value
                            {
                                fread(&ValueLength, sizeof(unsigned short), 1, fp); //Read Value Length (VL) - 16 bits
                                fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                fread(&sdata, sizeof(unsigned short), 1, fp); //Read Value Field (4 bytes as indicated by VL) printf("\tField=%d\n", ValueField);
                                fwrite(&sdata, sizeof(unsigned short), 1, ft);
                                if (sdata <= 5) pixelmax=256; //If no pixelmax data, set it of 256
                                else pixelmax = sdata;
                            }
                            else
                            {
                                if (strcmp(VR,"UL")==0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&SValueLength, sizeof(unsigned short), 1, ft);
                                    fread(&LValueField, sizeof(unsigned long), 1, fp);
                                    fwrite(&LValueField, sizeof(unsigned long), 1, ft);
                                }
                                else if (strcmp(VR,"FL")==0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp); //Read Value Length (VL) - 16 bits
                                    fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                    fread(&iLength, sizeof(unsigned int), 1, fp); //Read Value Field (4 bytes as indicated by VL)
                                    fwrite(&iLength, sizeof(unsigned int), 1, fp);
                                }
                                else if (strcmp(VR, "OB") == 0)
                                {
                                    fread(&ReservedField, sizeof(unsigned short), 1, fp);
                                    fwrite(&ReservedField, sizeof(unsigned short), 1, ft);
                                    fread(&ValueLength, sizeof(unsigned long), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned long), 1, ft);
                                    for (i=0; i<ValueLength; i++)
                                    {
                                        t = fgetc(fp);
                                        fputc(t,ft);
                                    }
                                }
                                else if (strcmp(VR, "SQ") == 0)
                                {
                                    fread(&ReservedField, sizeof(unsigned short), 1, fp);
                                    fwrite(&ReservedField, sizeof(unsigned short), 1, ft);
                                    fread(&ValueLength, sizeof(unsigned long), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned long), 1, ft);
                                    for (i=0; i<ValueLength; i++)
                                    {
                                        t = fgetc(fp);
                                        fputc(t, ft);
                                    }
                                }
     
                                else if (strcmp(VR, "CS") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                    String = new char[ValueLength+1];
                                    fgets(String, ValueLength+1, fp);
                                    fwrite(String, sizeof(char), ValueLength, ft);
                                    if (tag[0] == 0x08 && tag[1] == 0x60)   //Get Modality
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT9, CString(String));
                                    }
                                    else if (tag[0] == 0x08 && tag[1] == 0x08)   //Get Image Type
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT10, CString(String));
                                    }
                                    else if (tag[0] == 0x10 && tag[1] == 0x40)   //Get Patient's Gender
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT8, CString(String));
                                    }
                                }
                                else if (strcmp(VR, "SL") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                    fread(&LValueField, sizeof(unsigned long), 1, fp);
                                    fwrite(&LValueField, sizeof(unsigned long), 1, ft);
                                }
                                else if (strcmp(VR, "FL") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                    if (ValueLength == 4)
                                    {
                                        fread(&FValueField, sizeof(unsigned long), 1, fp);
                                        fwrite(&FValueField, sizeof(unsigned long), 1, ft);
                                    }
                                    else
                                    {
                                        String = new char[ValueLength];
                                        fgets(String, ValueLength+1, fp);
                                        fwrite(String, sizeof(char), ValueLength, ft);
                                    }
                                }
                                else if (strcmp(VR, "SL") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                                    fread(&LValueField, sizeof(unsigned long), 1, fp);
                                    fwrite(&LValueField, sizeof(unsigned long), 1, ft);
                                }
                                else if (strcmp(VR, "SS") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1 , ft);
                                    fread(&ValueField, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueField, sizeof(unsigned short), 1, ft);
                                }
                                else if (strcmp(VR, "US") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1 , ft);
                                    String = new char[ValueLength];
                                    fgets(String, ValueLength+1, fp);
                                    fwrite(String, sizeof(char), ValueLength, ft);
                                }
                                else if (strcmp(VR, "LT") == 0)
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1 , ft);
                                    for (i=0; i<ValueLength; i++)
                                    {
                                        t = fgetc(fp);
                                        fputc(t, ft);
                                    }
                                }
                                else
                                {
                                    fread(&ValueLength, sizeof(unsigned short), 1, fp);
                                    fwrite(&ValueLength, sizeof(unsigned short), 1 , ft);
                                    String = new char[ValueLength+1];
                                    fgets(String, ValueLength+1, fp);
                                    fwrite(String, sizeof(char), ValueLength, ft);
                                    if (tag[0] == 0x10 && tag[1] == 0x10)   //Get Patient's Name
                                    {
    // TagInfodlg.SetDlgItemText(IDC_EDIT4, CString(String));
                                        TagInfodlg.SetDlgItemText(IDC_EDIT4, CString("Undisclosed"));
                                    }
                                    else if (tag[0] == 0x10 && tag[1] == 0x20)   //Get Patient's ID
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT6, CString(String));
                                        Patient_ID = CString(String);
    // TagInfodlg.SetDlgItemText(IDC_EDIT6, CString("Undisclosed"));
                                    }
                                    else if (tag[0] == 0x10 && tag[1] == 0x1010)  //Get Patient's Age
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT7, CString(String));
                                    }
                                    else if (tag[0] == 0x18 && tag[1] == 0x50)   //Get Slice Thickness
                                    {
                                        slice_thickness = atof(String);
                                        TagInfodlg.SetDlgItemText(IDC_EDIT3, CString(String));
                                    }
                                    else if (tag[0] == 0x20 && tag[1] == 0x32)   //Get Image Position
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT11, CString(String));
                                    }
                                    else if (tag[0] == 0x8 && tag[1] == 0x70)   //Get Modality Manufacturer
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT12, CString(String));
                                    }
                                    else if (tag[0] == 0x28 && tag[1] == 0x30)   //Get Pixel Resolution
                                    {
                                        pixel_res = atof(String);
                                        TagInfodlg.SetDlgItemText(IDC_EDIT13, CString(String));
                                    }
                                    else if (tag[0] == 0x10 && tag[1] == 0x1030)
                                    {
                                        TagInfodlg.SetDlgItemText(IDC_EDIT14, CString(String));
                                    }
                                    else if (tag[0] == 0x20 && tag[1] == 0x13)   //Get Image Number
                                    {
                                        slice_img = CString(String);
                                        TagInfodlg.SetDlgItemText(IDC_EDIT15, CString(String));
                                    }
                                }
                            }
                        }
                        else
                        {
                            fread(&ValueLength, sizeof(unsigned short), 1, fp);
                            fwrite(&ValueLength, sizeof(unsigned short), 1, ft);
                            String=new char[ValueLength+1]; //Reading Value Length
                            fgets(String,ValueLength+1,fp);
                            fwrite(String, sizeof(char), ValueLength, ft);
                        }
                        /* else { //UID not supported here
                        CTransferSyntaxDialog adlg;
                        adlg.DoModal();
                        return;
                        } */
                    }
                }
    //----------------------- Code to read the pixel values of DICOM ---------------------------
                else if (tag[0] == 0x7FE0 && tag[1] < 0x0010)
                {
                    fread(&ValueLength, sizeof(unsigned int) , 1, fp);
                    fwrite(&ValueLength, sizeof(unsigned int) , 1, ft);
                    fread(&LValue, sizeof(unsigned long), 1, fp);
                    fwrite(&LValue, sizeof(unsigned long), 1, ft);
                    position = ftell(ft);
                    fclose(ft);
                }
     
                else
                {
                    pixelmax = -99999;
                    pixelmin = 99999;
    //************ Amended on 27 Sep 06 to display image in the correct orientation ************
     
                    if ((no_of_rows==512 && no_of_cols==512) || (no_of_rows==256 && no_of_cols==256))
                    {
                        for (i=0; i<no_of_rows; i++)
                        {
                            for (j=0; j<no_of_cols; j++)
                            {
                                fread(&pixelval, sizeof(short), 1, fp);
                                fwrite(&pixelval, sizeof(short), 1, ft);
                                if (pixelval>17000) pixelval=0;
                                if (pixelval<-2500) pixelval=0;
                                pixelvalue[((no_of_rows-1)-i)*no_of_cols + j] = pixelval;
                                pixelmax = (pixelval > pixelmax)? pixelval : pixelmax; //Find max pixel val for normalization
                                pixelmin = (pixelval < pixelmin)? pixelval : pixelmin; //Find min pixel val
                                maxpix = pixelmax;
                                pixelvalue[i] = pixelval;
                            }
                        }
                    }
                    else
                    {
                        for (i=0; i<no_of_rows; i++)
                        {
                            for (j=0; j<no_of_cols; j++)
                            {
                                fread(&pixelval, sizeof(short), 1, fp);
                                fwrite(&pixelval, sizeof(short), 1, ft);
                                if (pixelval>17000) pixelval=0;
                                if (pixelval<-2500) pixelval=0;
                                pixelvalue[((no_of_rows-1)-i)*256 + j] = pixelval;
                                pixelmax = (pixelval > pixelmax)? pixelval : pixelmax; //Find max pixel val for normalization
                                pixelmin = (pixelval < pixelmin)? pixelval : pixelmin; //Find min pixel val
                                maxpix = pixelmax;
                            }
                        }
                    }
    //******************************************************************************************
     
                    if (no_of_rows == 512)   //No duplicaion required
                    {
                        for (i=0; i<no_of_rows*no_of_cols; i++)
                        {
                            image[i] = (int)((float)(pixelvalue[i] - pixelmin)/(float)(pixelmax - pixelmin)*255.0f);
    // image2[i] = image[i];
                        }
                    }
                    else if (no_of_rows == 256)   //Duplication of 4 pixels required)
                    {
                        for (i=0; i<no_of_rows*no_of_cols; i++)   //For enlargement of 256 to 512
                        {
                            image256[i] = (int)((float)(pixelvalue[i]-pixelmin)/(float)(pixelmax - pixelmin)*255.0f); // Used for 3D side view
    // image2[i] = image256[i]; //Increment to next image pixel
                        }
                    }
     
                    else   //All other sizes use 256x256
                    {
                        i = 0;
                        for (j=0; j<256; j++)   //For enlargement of 256 to 512
                        {
                            for (k=0; k<256; k++)
                            {
                                image256[i] = (int)((float)(pixelvalue[i]-pixelmin)/(float)(pixelmax - pixelmin)*255.0f); // Used for 3D side view
                                i++; //Increment to next image pixel
                            }
                        }
                    }
                    flag = false; //Flag to stop the while loop to stop reading file
                    draw = true; //Flag to indicate draw during OnDraw
                }
            }
            fclose(fp);
            fclose(ft);
            delete String;
    //Invalidate();
    //UpdateWindow();
        }
        return;
    }
    
     
    Last edited by a moderator: Nov 2, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Not if you're not going to post properly formatted code. This lot is absolutely unreadable due to lack of indentation.
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Posted the properly indented code.

    @ beanbean :
    Plz do keep it in mind, when you post code here. I won't do it next time.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    It's very interesting to Google "CLEO_MedivisionView". Do you know metamofia? He seems to be working on the same project as you :)
    By the way I hope the two of you have permission to post this code all over the internet.
     

Share This Page