【问题标题】:how to read and write an image using C++ in visual studio with ITK configured如何在配置了 ITK 的 Visual Studio 中使用 C++ 读取和写入图像
【发布时间】:2019-03-18 16:44:56
【问题描述】:

我是 ITK 和 c++ 的初学者。我有以下代码,我可以在其中获取图像的高度和宽度。我不想在控制台中提供输入图像,而是想在代码本身中进行。如何直接将输入图像赋予这段代码?

#include "itkImage.h"
#include "itkImageFileReader.h"

int main()
{
mat m("filename");
imshow("windowname", m);
}
// verify command line arguments
if( argc < 2 )
{
std::cout << "usage: " << std::endl;
std::cerr << argv[0] << " inputimagefile" << std::endl;
return exit_failure;
}

 typedef itk::image<float, 2>            imagetype;
 typedef itk::imagefilereader<imagetype> readertype;

 readertype::pointer reader = readertype::new();
 reader->setfilename( argv[1] );
 reader->update();

 std::cout << reader->getoutput()->getlargestpossibleregion().getsize()[0] << " "
 << reader->getoutput()->getlargestpossibleregion().getsize()[1] << std::endl;

// an example image had w = 200 and h = 100 (it is wider than it is tall). the above output
// 200 100
// so w = getsize()[0]
// and h = getsize()[1]

// a pixel inside the region
itk::index<2> indexinside;
indexinside[0] = 150;
indexinside[1] = 50;
std::cout << reader->getoutput()- 
>getlargestpossibleregion().isinside(indexinside) << std::endl;

// a pixel outside the region
itk::index<2> indexoutside;
indexoutside[0] = 50;
indexoutside[1] = 150;
std::cout << reader->getoutput()-   >getlargestpossibleregion().isinside(indexoutside) << std::endl;

// this means that the [0] component of the index is referencing the left to right (column) index
// and the [1] component of index is referencing the top to bottom (row) index

return exit_success;
}

【问题讨论】:

    标签: c++ image-processing itk


    【解决方案1】:

    reader-&gt;setfilename( argv[1] ); 更改为reader-&gt;setfilename( "C:/path/to/file.png" );

    我认为

    mat m("filename");
    imshow("windowname", m);
    

    从一些不相关的代码中潜入?否则示例将无法编译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      相关资源
      最近更新 更多