[ITK-users] ImageSeriesWriter | SimpleITK

Matias Montroull matimontg at gmail.com
Tue Mar 24 17:25:20 EDT 2015


Sorry... I figured out:

here's the code that works, I missed to add the images using "i" as the
variable that changes in every iteration as well as specifying the full
path to the directory in the Add method

            ImageFileReader imgreader = new ImageFileReader();
            imgreader.SetFileName(path_pacientes + nombre_paciente +
@"\Fusion\" + "resultado.mha");
            itk.simple.Image imgtest = imgreader.Execute();
            ImageSeriesWriter SeriesWriter = new ImageSeriesWriter();
            VectorString vs = new VectorString();
            for (int i=0; i < imgtest.GetSize()[2]; ++i)
            {
                vs.Add(path_pacientes + nombre_paciente + @"\Fusion\Test\"
+ "imagen" + i + ".dcm");
            }

            SeriesWriter.SetFileNames(vs);

            SeriesWriter.Execute(imgtest, vs, false);

Thanks for all your help!

Matias.

On Tue, Mar 24, 2015 at 6:19 PM, Matias Montroull <matimontg at gmail.com>
wrote:

> Thanks Bradley,
>
> So, I did this:
>
>       ImageFileReader imgreader = new ImageFileReader();
>             imgreader.SetFileName(path_pacientes + nombre_paciente +
> @"\Fusion\" + "resultado.mha");
>             itk.simple.Image imgtest = imgreader.Execute();
>             ImageSeriesWriter SeriesWriter = new ImageSeriesWriter();
>             VectorString vs = new VectorString();
>             for (int i=0; i < imgtest.GetSize()[2]; ++i)
>             {
>                 vs.Add("imagen {0}.dcm");
>             }
>
>             SeriesWriter.SetFileNames(vs);
>             SeriesWriter.Execute(imgtest, vs, false);
>
> And I only get one file name (imagen {0}.dcm), am I missing something? (I
> wasn't able to do this: "name {0}.ext".Format(i))
>
> Thanks,
>
> Matias.
>
> On Tue, Mar 24, 2015 at 3:12 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>
> wrote:
>
>> Hello,
>>
>> On Mar 24, 2015, at 1:56 PM, Matias Montroull <matimontg at gmail.com>
>> wrote:
>>
>> //Here's where I struggle...
>>             vs.Add(path_pacientes + nombre_paciente +
>> @"\Fusion\SalidaTest\imagen%03d.dcm"); //Is this rthe right way to include
>> a vector of strings
>>
>>
>>
>> No that is not the write way. You actually need to create the list for
>> file names. You needs something closer to what's here in the C++ test [1]
>> but converted to CSharp. The length of the list must match the z size of
>> the images.
>>
>> Many languages have convenient generator expressions or list
>> comprehensions, which seems more natural than C printf formatting and the
>> perils associated with it.
>>
>> The long way to do it is just write a little for loop, something like:
>>
>> for (i=0; i < img.GetSize()[2], ++i)
>> vs.Add( "name {0}.ext".Format(i))
>>
>> Brad
>>
>> [1]
>> https://github.com/SimpleITK/SimpleITK/blob/master/Testing/Unit/IOTests.cxx#L123-L152
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150324/b5b40082/attachment.html>


More information about the Insight-users mailing list