GDCMSeriesFileNames fails to read folder with non ascii characters

I’m having trouble with code that worked just fine for years. I’m trying to open a DICOM dataset from Japan and my code cannot see any files of the series folder.

The code is (with placeholders for seriesUID and patient name :

... 
auto seriesUID = "1.2.3.4"; 
seriesPath = "F:\\Data\\Images\\Pat_MAXXXXXX MIXXXX=丸山___=マル___\\Study_a1753f72\\Series_10b36a87";

typedef itk::ImageSeriesReader<itk::Image<short, 3>> t_ImageSeriesReader;
t_ImageSeriesReader::Pointer imageSeriesReader = t_ImageSeriesReader::New();

typedef itk::GDCMImageIO t_ImageIOType;
t_ImageIOType::Pointer imageIO = t_ImageIOType::New();
imageSeriesReader->SetImageIO(imageIO);

typedef itk::GDCMSeriesFileNames t_NamesGeneratorType;
t_NamesGeneratorType::Pointer namesGenerator = t_NamesGeneratorType::New();
namesGenerator->SetDirectory(seriesPath);
imageSeriesReader->ReleaseDataBeforeUpdateFlagOn();
imageSeriesReader->AbortGenerateDataOff();

imageSeriesReader->SetFileNames(namesGenerator->GetFileNames(seriesUID));
...

On the last line, GetFileNames() returns an empty list; but I can see I have multiple files in the folder.
When I rename the folder to remove the Japanese characters then loading works fine.

Is there something that I am missing here ? I am using (and kinda stuck with) ITK 4.13

I have exactly the problem described here: I’m trying to open a DICOM dataset (in my case with Chinese characters in the directory) and GDCMSeriesFileNames won’t find the files in the folder.

When removing Chinese characters it works properly, but modifying the directory to remove non-ASCII characters is not an option for me. Any idea on this issue? I’m with latest ITK 5.2.

Thanks,
Nathan

Hi @nathanm ,

Perhaps setting the locale similar to this issue:

in itk::GDCMSeriesFileNames addresses the issue?

Hi @matt.mccormick , thank you for prompt reply.

I checked the link you provided and it seems pretty much related. How should I try this? Is it a branch of ITK to be merged with the bug fix? Or how do I set the locale?

Nathan

Hi Nathan,

To try a fix, set up a repository for contributing to ITK, a local build (more information can be found in The ITK Software Guide, then, like the patch did in itkGDCMImageIO.cxx, add std::locale currentLocale = std::locale::global(std::locale::classic()); and std::locale::global(currentLocale); around relevant blocks in itkGDCMSeriesFileNames.cxx.

Thanks,
Matt

In 3D Slicer, we switched to UTF-8 application code page and it solved all problems related to non-ASCII characters (except passing non-ASCII text via command-line arguments on Windows). On Linux and macOS UTF-8 code page should be the default, while on Windows you can enable this in the application manifest.

1 Like

Hi @matt.mccormick,

I tried a similar fix to the one you linked, with no success so far…

Hi @lassoan,

In order to enable this application manifest in Windows (WindowsApplicationUseUtf8.manifest), what’s the procedure to follow exactly? I’m using Visual Studio C++ to create a dynamic library (.dll).

Thank you,
Nathan

It cannot be set in a DLL, it must be set in the application. See how it is done in CTK at the link that I provided above.