I can‘t open a bmp image using vtkbmpreader

vtkSmartPointerReader = vtkSmartPointer::New();
//Reader->SetAllow8BitBMP(16);
Reader->SetDataScalarTypeToUnsignedChar();
Reader->SetFileDimensionality(3);
Reader->SetFilePrefix(“/home/yanghantao/Documents/ruxian/”);
//Reader->SetFileNameSliceSpacing(1);
Reader->SetFilePattern(“%s%03d_R.bmp”);
Reader->SetDataExtent(0, 2047, 0, 2047, 1, 30);
Reader->SetDataSpacing(1, 1, 10);
Reader->Update();

ERROR: In /home/yanghantao/Documents/VTK-8.2.0/IO/Image/vtkImageReader2.cxx, line 595
vtkBMPReader (0xe0f1b0): Initialize: Could not open file /home/yanghantao/Documents/ruxian/000_R.bmp

Hello,

An inaccessible file may be caused by a multitude of factors.

The usual checklist applies (assuming you are on some Unix-like system):

  • Do an ls /home/yanghantao/Documents/ruxian/000_R.bmp to test whether it exists or is accessible if any of those directories was mounted from some network share.
  • Do a cat /home/yanghantao/Documents/ruxian/000_R.bmp to test whether you have at least read access to it.
  • Do an ls on each directory all the way down to the file to test whether you have the execution flag set properly on each of them.
  • Open /home/yanghantao/Documents/ruxian/000_R.bmp in another program to rule out file corruption.

TIP: place your code between two ``` so it doesn’t get parsed by the markup parser.

regards,

Paulo

Thank you, I have solved my problem.

How did you solve it? Others may run into the same problem in the future.

Actually,I don’t really know why. I use another way to reader my series of image. But it seems that reader->SetAllow8BitBMP(16) is necessarly.

        vtkSmartPointer <vtkStringArray> fileArray = 
                        vtkSmartPointer< vtkStringArray >::New();
        char fileName[128];
        for(int i = 1; i < 31; i++)
        {
            sprintf(fileName,"/home/yanghantao/Documents/ruxian/%03d_R.bmp", i);
            std::string fileStr(fileName);
            fileArray->InsertNextValue(fileStr);
        }

        //read BMP
        vtkSmartPointer<vtkBMPReader> reader = vtkSmartPointer<vtkBMPReader>::New();
        reader->SetFileNames(fileArray);
        reader->SetAllow8BitBMP(16);

Another quetion about the code Reader->SetDataExtent(0, 2047, 0, 2047, 1, 30); I have already I set the fifth and sixth parameters to be 1 and 30 respectively. Why my console show me Could not open file /home/yanghantao/Documents/ruxian/000_R.bmp. Actually I didn’t let him to read the 000_R.bmp

Hello,

I suggest you to use a debugger to track down the source of that incorrect string. Your loop starts with 1. So why you’re getting an all-zero path you have to probe your code carefully. I’d certainly avoid those dreaded char *-based C functions like printf and the sort. They are common sources of hard-to-find bugs. Try using modern C++ replacements like:

#include <sstream>
#include <iomanip>

(...)

std::string filename;
(...)
   std::stringstream ss;
   ss << "/home/yanghantao/Documents/ruxian/" << std::setw(3) << std::setfill('0') << i << "_R.bmp";
   filename = ss.str();
(...)

take care,

Paulo