如何在Visual Studio中使用ITK配置的C 读取图像
how to read and write an image using C++ in visual studio with ITK configured
我是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;
}
通过 reader->setfilename( "C:/path/to/file.png" );
reader->setfilename( argv[1] );
我假设
mat m("filename");
imshow("windowname", m);
从一些无关的代码中潜入?否则该示例将不会编译。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 无法找到/读取配置文件.conf-FileIOException
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 一种在C++中读取TXT配置文件的简单方法
- 生成MRPT库时cmake配置失败
- FFMPEG配置文件级别id大小无效
- 如何通过Conan和CMake找到用于pkg配置的.pc文件
- 配置文件解析器仅返回以前的值
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 是否可以配置提升日志刷新?
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- C/C++:打印(配置)头文件的内容
- 配置:错误:找不到 MySQL 包含目录
- 安装 psutil 和为 pypy 配置期间出错
- 叮当格式化程序多行格式配置错误
- 使用 Eclipse CDT 进行 Cplex 配置
- 为c++配置Visual studio代码
- 如何定义自定义生成配置类型,其中通常是.exe的目标改为 DLL
- 如何在Visual Studio中使用ITK配置的C 读取图像