简体   繁体   中英

vtk convert 2d image to 3d (c++)

I've been reading the doxygen and the vtk wiki for days and I'm still not 100% sure what I'm asking is even possible.

What I want to accomplish is to take an input 2d image in a common format(ie PNG) and output a 3d model(PNG -> Model/Mesh or 2d -> 3d). A good example of this would be that if I draw a cube in MS paint and save the drawing as a PNG, then read the image and produce a 3d model of that cube. So my first question is is this possible? IT seems like there should be some way of taking the image data and converting to polydata and doind the model building from there. This is what I have in mind(in c++):

int main(int argc, char *argv[])
{
//Verify correct number of input arguements 
if(argc < 2)
{
    fprintf(stderr, "Usage: %s Filename(.png)\n");
    return EXIT_FAILURE;
}   
std::string fileName = argv[1];
//Read file
vtkSmartPointer<vtkImageReader2Factory> readerFactory =         vtkSmartPointer<vtkImageReader2Factory>::New();
vtkImageReader2 *imageReader = readerFactory->CreateImageReader2(inputFilename.c_str());
imageReader->Update();

//Get the image Data
    vtkSmartPointer<vtkImageDataGeometryFilter> imageDataGeometryFilter = 
vtkSmartPointer<vtkImageDataGeometryFilter>::New();

imageDataGeometryFilter->SetInputConnection(imageReader->GetOutputPort()); imageDataGeometryFilter->Update();

So, if the answer to the first question is yes, does this appear to be even remotely on the right track?

I doubt VTK provides ready algorithm addressing generic 2d shape into 3d model. This is basically an inverse problem, meaning the solutions could be many; without applying some constraints or assumptions of the object shape, it would be difficult.

VTK probably helps you to express the steps in processing the images (eg extracting the salient features, such as corners and lines), as well as providing with more choices in the data structure. The ideas shown in your code looks to me only show a general processing pipeline from 2d to 3d but the detail (the geometry filter for example) may need to be implemented by your own.

The actual task that you would like to accomplish is an algorithmic problem which is of research interest in CAD domain (well defined 2d engineering drawing into 3d model) for example this work .

Projecting a 3D object to a 2D plane, and rasterizing it, is not a reversible process, as a lot of information is lost while doing so (depth, hidden surfaces, topology, etc). All you can do is trying to recover that lost pieces of information by smart guesses.

Even highly specialized systems with stereoscopic vision, considerable parallel processing power and a huge database of contextual information -- humans -- can easily get fooled at that ( optical illusion , trompe l'oeil ).

Solving that with a computer is horribly complex, and the result most likely disappointing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM