[ITK] Decode a medical image from memory buffer in ITK

Matt McCormick matt.mccormick at kitware.com
Wed Oct 26 13:46:38 EDT 2016


Hi Fijoy,

While this approach does not apply as-is when the buffer is in a
format like DICOM, reading an image from an in memory by passing the
address and possibly also the metadata through the FileName is
demonstrated here:

  https://github.com/InsightSoftwareConsortium/ITK/blob/33e56685e6bc2323cdff9457fb48b7967c60a6e5/Modules/IO/ImageBase/test/itkFileFreeImageIO.h

  https://github.com/Slicer/Slicer/blob/d4b177c3c78d6ebc6ddcee7d7e0ba917652e0026/Libs/MRML/IDImageIO/itkMRMLIDImageIO.h

HTH,
Matt

On Mon, Oct 24, 2016 at 1:18 PM, Francois Budin
<francois.budin at kitware.com> wrote:
> Hi Fijoy,
>
> ITK will need the image information such as the size and the dimension to
> know what your buffer corresponds to. If you do have these informations then
> you can use the import filter Dženan mentioned. If you do not have these
> informations, then
> there is no way for ITK to know if your image has dimension (x*y*z)*(1)*(1)
> or (x*y)*(z)*(1) or any possible combination that would lead to the same
> buffer size.
> Hope this helps,
>
> Francois
>
> On Mon, Oct 24, 2016 at 11:23 AM, Dženan Zukić <dzenanz at gmail.com> wrote:
>>
>> Hi Fijoy,
>>
>> as far as I am aware, there is no class to read an image from buffer
>> instead of file. But the possible workaround is to write that buffer into a
>> file in temp folder and read that file.
>>
>> HTH,
>> Dženan
>>
>> On Mon, Oct 24, 2016 at 11:13 AM, Fijoy Vadakkumpadan <tofijoy at gmail.com>
>> wrote:
>>>
>>> Hi Dženan,
>>>
>>> Correct me if I'm wrong, but the Import filter assumes that I have the
>>> medical image metadata (size, resolution, etc.), and the decompressed data
>>> (the C-array). However, I do not have these.
>>>
>>> All I have is a buffer buf containing the encoded image, i.e., buf is
>>> filled like so:
>>>
>>> unsigned char buf[MAX_FILE_SIZE];
>>> f = fopen("myImage.dcm", "rb");
>>> n = fread(buf, MAX_FILE_SIZE, 1, f);
>>>
>>> In other words, I'm looking for a class that can read an image from a
>>> buffer, just like ImageFileReader reads from a file. Does such a class
>>> exist?
>>>
>>> Thanks,
>>> Fijoy
>>>
>>> On Mon, Oct 24, 2016 at 10:57 AM, Dženan Zukić <dzenanz at gmail.com> wrote:
>>>>
>>>> Hi Fijoy,
>>>>
>>>> that is the job of Import filter.
>>>>
>>>> Regards,
>>>> Dženan
>>>>
>>>> On Mon, Oct 24, 2016 at 10:50 AM, Fijoy Vadakkumpadan
>>>> <tofijoy at gmail.com> wrote:
>>>>>
>>>>> Hi all,
>>>>>
>>>>> I'm wondering if ITK can decode a medical image from a buffer.
>>>>>
>>>>> For example, if I have a DICOM file read into a buffer buf using
>>>>> fread(), is there an API in ITK that I can use to get an itk::Image pointer
>>>>> from buf?
>>>>>
>>>>> Thank you,
>>>>> Fijoy
>>>>>
>>>>> _______________________________________________
>>>>> Community mailing list
>>>>> Community at itk.org
>>>>> http://public.kitware.com/mailman/listinfo/community
>>>>>
>>>>
>>>
>>
>>
>> _______________________________________________
>> Community mailing list
>> Community at itk.org
>> http://public.kitware.com/mailman/listinfo/community
>>
>
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>


More information about the Community mailing list