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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Save single DCM to multipage DCM

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
AlphaUniform Posted - Feb 25 2019 : 12:25:59
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
3   L A T E S T    R E P L I E S    (Newest First)
AlphaUniform Posted - Feb 26 2019 : 00:52:06
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
xequte Posted - Feb 25 2019 : 15:53:33
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
xequte Posted - Feb 25 2019 : 15:26:59
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