ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Save single DCM to multipage DCM
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AlphaUniform

30 Posts

Posted - Feb 25 2019 :  12:25:59  Show Profile  Reply
Hi all,
I'm wondering if I can use ImageEn for converting single frame dicom to multiframe dicom.
Here is what I tried:


TIEMultiBitmap *bmpM = new TIEMultiBitmap();
	TImageEnMIO *pMIO = new TImageEnMIO(bmpM);

	int iWidth = 0;
	int iHeight = 0;
	int iSamples = 0;
	int iBits = 0;
	int iStored = 0;
	for(int i=0; i<sl->Count; i++)
	 {
		TIEBitmap *bmp = new TIEBitmap();
		TImageEnIO *pIO = new TImageEnIO(bmp);
		
		pIO->LoadFromFileDICOM(sl->Strings[i]);

		if(iWidth == 0)
		 {
			iWidth = bmp->Width;
			iHeight = bmp->Height;
			iSamples = pIO->Params->SamplesPerPixel;
			iStored = pIO->Params->BitsPerSample;
			iBits = bmp->BitCount;
		 }
		else
		 {
			if(iWidth != bmp->Width || iHeight != bmp->Height || iSamples != pIO->Params->SamplesPerPixel || iBits != bmp->BitCount
				|| iStored != pIO->Params->BitsPerSample)
			 {
//Just for breakpoint
				iWidth = bmp->Width;
				iHeight = bmp->Height;
			 }
		 }

		bmpM->AppendImage(bmp);

		delete pIO;
		delete bmp;
	 }
	delete sl;

	pMIO->SaveToFileDICOM("C:\\temp\\multidicom.dcm", false);
	delete pMIO;
	delete bmpM;


I'm always get the error "DICOM saving: different images", but I'm pretty sure, that Width, Height, Bitcount, etc. is the same in all single frames.
(If I use SaveToFile instead of SaveToFileDICOM, I'm getting a 0 byte file.)

Can anyone tell me, what I'm doing wrong? I read something about setting params for each frame, but I keep failing.

Thanks in advance.
Alex

xequte

38564 Posts

Posted - Feb 25 2019 :  15:26:59  Show Profile  Reply
Hi Alex

Unfortunately DICOM format requires each frame to be both the same size and pixel format. So if you are receiving the "different images" error, one or more of the following has changed between frames:
- Bitmap.Width
- Bitmap.Height
- Bitmap.Params.BitsPerSample
- Bitmap.Params.SamplesPerPixel


The following code works if all source images have matching size and pixel format properties:

procedure TForm1.Button1Click(Sender: TObject);
var
  bmpM: TIEMultiBitmap;
  bmp : TIEBitmap;
  i: Integer;
begin
  bmpM := TIEMultiBitmap.Create;
  bmpM.ParamsEnabled := True;

  for i := 0 to sl.count-1 do
  begin
    bmp := TIEBitmap.Create();
    bmp.ParamsEnabled := True;
    bmp.Read(sl[i]);
    bmpM.AppendImage(bmp);
    bmp.Free;
  end;

  bmpM.Write( 'D:\multidicom.dcm', ioDICOM );
  bmpM.Free;
end;


In your case, you might want to iterate through each frame, updating the pixel format, BitsPerSample and SamplesPerPixel, and if necessary, the size.

Here is an example of that:

procedure TForm1.Button1Click(Sender: TObject);
var
  mbmp: TIEMultiBitmap;
  mio: TImageEnMIO;
  bmp : TIEBitmap;
  i: Integer;
begin
  mbmp := TIEMultiBitmap.create;
  mio := TImageEnMIO.CreateFromIEMBitmap(mbmp);
                  
  for i := 0 to sl.count-1 do
  begin
    bmp := TIEBitmap.Create();
    bmp.ParamsEnabled := True;
    bmp.Read(sl[i]);
    mbmp.AppendImage(bmp);
    bmp.Free;
  end;     

  // Ensure all frames of DICOM are same size
  for I := 1 to mbmp.Count - 1 do
  begin
    bmp := mbmp.GetTIEBitmap( I );
    bmp.Resample( mbmp.ImageWidth[0], mbmp.ImageHeight[0], rfFastLinear );
    mbmp.ReleaseBitmap( I, True );
  end;

  // Ensure all frames of DICOM have same duplication and pixel format info
  mio.DuplicateCompressionInfo();

  mio.SaveToFileDICOM( 'D:\multidicom3.dcm' );
  mio.Free;
  mbmp.free;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38564 Posts

Posted - Feb 25 2019 :  15:53:33  Show Profile  Reply
FYI, for the next version, there will be different exceptions:

'DICOM saving: Frame sizes do not match'
'DICOM saving: Frame pixel formats do not match'

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AlphaUniform

30 Posts

Posted - Feb 26 2019 :  00:52:06  Show Profile  Reply
Hi Nigel,
thank you very much for your fast reply.


TIEMultiBitmap *bmpM = new TIEMultiBitmap();
	bmpM->ParamsEnabled = true;

	
	for(int i=0; i<sl->Count; i++)
	 {
		TIEBitmap *bmp = new TIEBitmap();
		bmp->ParamsEnabled = true;
		bmp->Read(sl->Strings[i]);
		bmpM->AppendImage(bmp);
		delete bmp;
	 }
	delete sl;
	bmpM->Write("C:\\temp\\multidicom.dcm");
	delete bmpM;


worked.
So I guess it was the ParamsEnabled = true; flag, that was missing in my code, because I loaded with EnIO.

Best regards
Alex
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: