[Dcmlib] Re: write dicom to unsigned short

Jean-Pierre Roux Jean-Pierre.Roux at creatis.insa-lyon.fr
Wed Jan 11 14:15:12 CET 2006


acid wrote:

>Dear sir, 
>so are we very sure that 
>codes below can write 16bits dicom? (cause I tried but still it output unsigned char)
>Thanks a lot.
>I have been trapped in here very long...
>  
>

Hi, Alison.
Let me ask some more questions :
You read a dicom file, nad for doing that, you create a gdcm::File, 
called 'm_dicom', and then a gdcm::FileHelper, called 'm_dicomHelper'.
You get the Pixels in m_imageData.
OK.

Then, you allocate an area called 'output', an you copy the pixels in it.
I guess you know what you are doing.
OK.

Then you set the values for Rows, Columns, Samples Per Pixels, etc, 
using an object called 'm_dicomheader'.
I suppose it's a gdcm::File.
Am I right?

Then you SetImageData, SetWriteModeToRaw, etc, using an object called 'm_dicomWrite'.
I suppose it'a gdcm::FileHelper, constructed with something like :

m_dicomWrite = gdcm::FileHelper::New(m_dicomheader);
Am I right?

If I am, I would say the program is OK, and the resulting image *cannot* be an 'unsigned char' one.
:-(

Could you send me an image written with this program, so I can look inside the header to try to understand what's going wrong with it.
Thx
JP


>bool IMT_DICOMInfo::ReadHandler ( const char* infile )
>{		
>	m_dicom = gdcm::File::New( );
>	m_dicom->SetFileName( infile );
>	m_dicom->Load();
>	
>	m_dicomHelper = gdcm::FileHelper::New(m_dicom);
>---omitted-----
>}
>
>
>PixelData2D<unsigned short>* IMT_DICOMInfo::Read (PixelData2D<unsigned short> *output)
>{
>	m_imageData= m_dicomHelper->GetImageData();
>   	m_dataSize = m_dicomHelper->GetImageDataSize();
>
>
>	if(output == NULL)
>	{
>		output = new PixelData2D<unsigned short> (m_xdim, m_ydim, m_Nchannel);
>	}
>	else
>	{
>		bool bSizeTest = output->SizeEqual(m_xdim, m_ydim, m_Nchannel);
>		if(!bSizeTest) 
>		{
>			printf("Size of input is not equal to image!\n");
>			return 0;
>		}
>	}	
>
>
>	int i,j,c;
>	if(m_Nchannel != 0)
>	{
>		for(j=0; j < m_ydim; j++)
>		{
>			for(c=0; c < m_Nchannel; c++)
>			{
>				for(i=0; i < m_xdim; i++)
>				{
>		 			output->m_buffer[j][i][c] =
>						((unsigned short*)m_imageData)[i+c+m_xdim*m_Nchannel*j];
>				}		
>			}
>		}
>	}
>
>	return output;
>}
>
>
>void IMT_DICOMInfo::Write (PixelData2D<unsigned short> *output)
>{
>
>	char szTmp[10];
>	sprintf( szTmp, "%d", output->m_uXDim );
> 	m_dicomheader->InsertEntryString(szTmp,0x0028,0x0011); // Columns
>    
>	sprintf( szTmp, "%d", output->m_uYDim );
>	m_dicomheader->InsertEntryString(szTmp,0x0028,0x0010); // Rows
>	
>	sprintf( szTmp, "%d", output->m_uNChannel );
>	m_dicomheader->InsertEntryString(szTmp,0x0028,0x0002); // Samples per Pixel
>
>
>	printf("++++++++++++++++++++unsigned short\n");
>	std::ostringstream str;
>	str.str("");
>	str <<16;
>  	  m_dicomheader->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated
>	
>	str.str("");
>  	  str << 16;
>	m_dicomheader->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored
>	
>	str.str("");
>   	 str <<15;
>    	m_dicomheader->InsertEntryString(str.str(),0x0028,0x0102); // High Bit
>    
>	str.str("");
>   	 str << "0"; // Unsigned
>   	 m_dicomheader->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation
>	
>//	SetInfo();
>
>	int size=output->m_uXDim*output->m_uYDim*output->m_uNChannel*sizeof(unsigned short);
>
> 
>	m_dicomWrite->SetImageData((unsigned char *)output->m_buffer[0][0],size);
>	m_dicomWrite->SetWriteModeToRaw();
>	m_dicomWrite->SetWriteTypeToDcmExplVR();
>	m_dicomWrite->Write(m_out);
>}
>
>
>
>
>-----Original Message-----
>From: Jean-Pierre Roux [mailto:jpr at creatis.insa-lyon.fr]
>Sent: Monday, January 02, 2006 10:40 PM
>To: acid; Dcmlib at creatis.insa-lyon.fr
>Subject: Re: write dicom to unsigned short
>
>
>acid wrote:
>
>  
>
>>Dear sir,
>>I try to write dicom to unsigned short
>>and my code is what below
>>but the output will look like "unsigned char",
>>I wonder which information should be set to the output dicom
>>to have a correct result,
>> 
>>
>>    
>>
>
>Did you set the image sizes?
>
>m_dicomw->InsertEntryString(strCol.str(),0x0028,0x0011); // Columns
>m_dicomw->InsertEntryString(strRow.str(),0x0028,0x0010); // Rows
>
>And the pixels characteristics?
>
> Bits Allocated (=16) , Bits Stored (=16), High Bit (=15), Pixel Representation (=1)
>
>// and, if image is RGB
> Samples Per Pixel (=3 ) 
> PlanarConfiguration (=1) 
>
>
>  
>
>>thanks again!
>>
>>Sincerely,Alison
>>
>>void IMT_DICOMInfo::Write (PixelData2D<unsigned short> *output)
>>{
>>	UnsShortSetInfo();
>>	int size=output->m_uXDim*output->m_uYDim*output->m_uNChannel*sizeof(unsigned short);
>>
>>	m_dicomWrite->SetImageData((unsigned char *)output->m_buffer[0][0],size);
>>	m_dicomWrite->SetWriteModeToRaw(); // no LUT, no compression.
>>	m_dicomWrite->SetWriteTypeToDcmExplVR();
>>
>>  if( !m_dicomWrite->Write(m_out ) )
>>  {
>>		printf("not writable/n");     
>>  }
>>
>>  m_dicomWrite->Delete();
>>}
>>
>> 
>>
>>    
>>
>
>  
>




More information about the Dcmlib mailing list