Re: [Gdcm2] Java: pass an image for decompression as byte data
Cross-platform DICOM implementation
Brought to you by:
malat
|
From: Mathieu M. <mat...@gm...> - 2022-11-22 07:20:06
|
Hi Mikhail No this is not possible right now. Someone would need to implement proper swig wrapping for this feature. On Mon, Nov 21, 2022 at 6:35 PM Mikhail Timofeev <mt...@ou...> wrote: > > Thanks again for responding. Another related question I have is how to acquire the image metadata from the image byte array (when we cannot use ImageHelper.GetDimensionsValue(File)). I think the same problem exists in C# as well, since the relevant values are also hardcoded in this example: > https://github.com/malaterre/GDCM/blob/e501d71938a0889f55885e4401fbfe60a8b7c4bd/Examples/Csharp/DecompressJPEGFile.cs#L58 > Is it possible with current APIs in Java at all? > I think it would be a non-issue, if swig has correctly mapped the StreamImageReader class to java - but it does not, since it cannot map std::istream. > > best regards > Mikhail > > > ________________________________ > From: Mathieu Malaterre <mat...@gm...> > Sent: Thursday, November 10, 2022 08:26 > To: Mikhail Timofeev <mt...@ou...> > Cc: gdc...@li... <gdc...@li...> > Subject: Re: [Gdcm2] Java: pass an image for decompression as byte data > > On Thu, Nov 10, 2022 at 8:23 AM Mathieu Malaterre > <mat...@gm...> wrote: > > > > Hi, > > > > On Wed, Nov 9, 2022 at 7:52 PM Mikhail Timofeev <mt...@ou...> wrote: > > > > > > Hi all, > > > I am trying to create a program similar to the Examples/Java/DecompressImage but with the difference that I would like to read in the file in Java and pass the byte data to gdcm for decompression, ideally avoiding having to copy the data. Anyway here is my naive approach (which does not work): > > > > > > ImageChangeTransferSyntax change = new ImageChangeTransferSyntax(); > > > change.SetTransferSyntax( new TransferSyntax(TransferSyntax.TSType.ImplicitVRLittleEndian) ); > > > > > > byte[] bytes = Files.readAllBytes( Paths.get(file1)); > > > > > > DataElement dataElementIn = new DataElement(); > > > dataElementIn.SetArray( bytes, bytes.length ); > > > Bitmap bitmap = new Bitmap(); > > > > Do not create your own Bitmap, this is a subclass of Object and is not > > well supported in the swig wrapping. > > > > Simply re-use the one from the ImageChangeTransferSyntax, eg: > > > > Bitmap bitmap = change.GetOutput(); > > Meant to say -obviously-: > > Bitmap bitmap = change.GetInput(); > > > > > > > > bitmap.SetDataElement( dataElementIn ); > > > change.SetInput( bitmap ); > > > > > > if( !change.Change() ) > > > { > > > throw new Exception("Could not change: " + file1 ); > > > } > > > Bitmap image = change.GetOutput(); > > > > > > There are multiple issues here I suppose. But the actual error is this one thrown in the very last line: > > > > > > terminate called after throwing an instance of 'std::bad_cast' > > > what(): std::bad_cast > > > > > > Does anybody have any hints how proceed with this? Or maybe even an example of how this should be properly done? > > > Thanks and best regards > > > MT > > > _______________________________________________ > > > Gdcm-developers mailing list > > > Gdc...@li... > > > https://lists.sourceforge.net/lists/listinfo/gdcm-developers > > > > > > > > -- > > Mathieu > > > > -- > Mathieu -- Mathieu |