当前位置: 首页>>代码示例>>C++>>正文


C++ ImageIO类代码示例

本文整理汇总了C++中ImageIO的典型用法代码示例。如果您正苦于以下问题:C++ ImageIO类的具体用法?C++ ImageIO怎么用?C++ ImageIO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ImageIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doSeparate

static void doSeparate(Options& opts, StringVector& args) {
    if (!opts.GetBool("--separate")) {
        return;
    }

    ImageIO<DisplacementFieldType> io;
    DisplacementFieldType::Pointer input = io.ReadImage(args[0]);

    for (int i = 0; i < DisplacementFieldType::PixelType::Length; i++) {
        ImageIO<RealImage> realIO;
        RealImage::Pointer output = realIO.NewImageS<DisplacementFieldType>(input);

        RealImage::PixelType* oBuf = output->GetBufferPointer();
        itk::ImageRegionConstIteratorWithIndex<DisplacementFieldType> iter(input, input->GetBufferedRegion());

        int j = 0;
        for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter, j++) {
            DisplacementFieldType::PixelType p = iter.Get();
            oBuf[j] = p[i];
        }

        realIO.WriteImage(args[i+1], output);
    }
    end();
}
开发者ID:fayhot,项目名称:gradworks,代码行数:25,代码来源:particlesRun.cpp

示例2: main

int main(int argc, char* argv[]) {
    CSimpleOpt::SOption specs[] = {
        { 0, "-o", SO_REQ_SEP },
        SO_END_OF_OPTIONS
    };

    Options argParser;
    StringVector args = argParser.ParseOptions(argc, argv, specs);

    if (args.size() < 1) {
        cout << argv[0] << " [input-vector] [output-rgb]" << endl;
        return 1;
    }

    ImageIO<DeformFieldImageType> io;
    DeformFieldImageType::Pointer img = io.ReadImage(args[0]);

//    itk::UnaryFunctorImageFilter<DeformFieldImageType,RGBImageType> CastFilter;
    typedef itk::UnaryFunctorImageFilter<DeformFieldImageType, RGBImageType, Vector2RGB> CastFilter;
    CastFilter::Pointer caster = CastFilter::New();
    caster->SetInput(img);
    caster->Update();
    RGBImageType::Pointer rgbImg = caster->GetOutput();

    rgbImg->Print(cout);
    io.WriteImageS<RGBImageType>(args[1], rgbImg);

    return 0;
}
开发者ID:fayhot,项目名称:gradworks,代码行数:29,代码来源:krgb.cpp

示例3: runExpr1

// draw gaussian like line
void runExpr1(StringVector &args) {
    if (args.size() < 2) {
        cout << "--expr1 [output-real-image] [bending-height]" << endl;
        return;
    }

    float bendingHeight = atof(args[1].c_str());
    int bandWidth = 12;

    ImageIO<RealImage2> io;
    RealImage2::Pointer canvas = io.NewImageT(300, 200, 1);

    for (int x = 25; x < 275; x++) {
        double xx = (x - 150) * 0.1;
        double y = 150 - bendingHeight * exp(-xx*xx/100);

        RealImage2::IndexType realIdx;
        for (int j = y; j >= y - bandWidth; j--) {
            realIdx[0] = x;
            realIdx[1] = j;
            canvas->SetPixel(realIdx, 1);
        }
    }

    io.WriteImage(args[0], canvas);
}
开发者ID:fayhot,项目名称:gradworks,代码行数:27,代码来源:particlesRun.cpp

示例4: DrawPolyList

void DrawPolyList(const char *filename, list<TPPLPoly> *polys) {
	Image img(500,500);
	Image::Pixel white={255,255,255};
	img.Clear(white);

	ImageIO io;
	list<TPPLPoly>::iterator iter;

	tppl_float xmin = std::numeric_limits<tppl_float>::max();
	tppl_float xmax = std::numeric_limits<tppl_float>::min();
	tppl_float ymin = std::numeric_limits<tppl_float>::max();
	tppl_float ymax = std::numeric_limits<tppl_float>::min();
	for(iter=polys->begin(); iter!=polys->end(); iter++) {
		for(int i=0;i<iter->GetNumPoints();i++) {
			if(iter->GetPoint(i).x < xmin) xmin = iter->GetPoint(i).x;
			if(iter->GetPoint(i).x > xmax) xmax = iter->GetPoint(i).x;
			if(iter->GetPoint(i).y < ymin) ymin = iter->GetPoint(i).y;
			if(iter->GetPoint(i).y > ymax) ymax = iter->GetPoint(i).y;
		}
		//if(iter->GetOrientation() == TPPL_CCW) printf("CCW\n");
		//else if (iter->GetOrientation() == TPPL_CW) printf("CW\n");
		//else printf("gfdgdg\n");
	}
	//printf("\n");

	for(iter=polys->begin(); iter!=polys->end(); iter++) {
		DrawPoly(&img, &(*iter), xmin, xmax, ymin, ymax);
	}

	io.SaveImage(filename,&img);
}
开发者ID:BackupGGCode,项目名称:polypartition,代码行数:31,代码来源:test.cpp

示例5: runVector2Mat

void runVector2Mat(StringVector& args) {
    ImageIO<VectorImage2> io;
    VectorImage2::Pointer inputImage = io.ReadImage(args[0]);

    typedef itk::ImageRegionConstIteratorWithIndex<VectorImage2> VectorImageIteratorType;
    VectorImageIteratorType iter(inputImage, inputImage->GetBufferedRegion());

    ofstream ofs[2];
    ofs[0].open(args[1].c_str());
    ofs[1].open(args[2].c_str());

    VectorImage2::SizeType inputSize = inputImage->GetBufferedRegion().GetSize();

    VectorType* buffer = inputImage->GetBufferPointer();
    for (int j = 0; j < inputSize[1]; j++) {
        for (int i = 0; i < inputSize[0]; i++) {
            VectorType& vv = *buffer;
            for (int k = 0; k < 2; k++) {
                ofs[k] << vv[k] << " ";
            }
            ++buffer;
        }
        for (int k = 0; k < 2; k++) {
            ofs[k] << endl;
        }
    }

    for (int k = 0; k < 2; k++) {
        ofs[k].close();
    }
}
开发者ID:fayhot,项目名称:gradworks,代码行数:31,代码来源:particlesRun.cpp

示例6: doSlice

static void doSlice(Options& opts, StringVector& args) {
    if (!opts.GetBool("--slice")) {
        return;
    }
    if (args.size() < 4) {
        cout << "--slice dim index imagefile outputfile" << endl;
        die();
    }

    int dim = atoi(args[0].c_str());
    int slice = atoi(args[1].c_str());

    ImageIO<RealImage3> io;
    ImageInfo info;
    RealImage3::Pointer image = io.ReadCastedImage(args[2], info);
    RealImage2Vector sliceImages = SliceVolume(image, dim);

    if (slice < sliceImages.size()) {
        ImageIO<RealImage2> wio;
        wio.WriteCastedImage(args[3], sliceImages[slice], info.componenttype);
    } else {
        cout << "slice index is out of range" << endl;
    }
    end();
}
开发者ID:fayhot,项目名称:gradworks,代码行数:25,代码来源:particlesRun.cpp

示例7: SixFringeDecoder

shared_ptr<Codec> SixFringeCodecOptionsController::getCodec(void)
{
  QString sourceFilename = sourceFileBox->text();
  string str = sourceFilename.toLocal8Bit().constData();

  shared_ptr<SixFringeDecoder> codec = shared_ptr<SixFringeDecoder>(new SixFringeDecoder(str));
  codec->setGammaCutoff(gammaCutoffBox->value());
  codec->setScalingFactor(scalingBox->value());

  if(loadReferenceCheckbox->isChecked() && !shortReferenceFileBox->text().isEmpty() && !longReferenceFileBox->text().isEmpty())
  {
	ImageIO io;
	shared_ptr<IplImage> shortImage(io.readImage(shortReferenceFileBox->text().toAscii().constData()), [](IplImage* ptr) { cvReleaseImage(&ptr); });
	shared_ptr<IplImage> longImage(io.readImage(longReferenceFileBox->text().toAscii().constData()), [](IplImage* ptr) { cvReleaseImage(&ptr); });

	codec->setReferencePlane(shortImage, longImage);
  }

  return codec;
}
开发者ID:karpinsn,项目名称:SLS,代码行数:20,代码来源:SixFringeCodecOptionsController.cpp

示例8: DrawPoly

void DrawPoly(const char *filename, TPPLPoly *poly) {
	Image img(500,500);
	Image::Pixel white={255,255,255};
	img.Clear(white);
	ImageIO io;

	tppl_float xmin = std::numeric_limits<tppl_float>::max();
	tppl_float xmax = std::numeric_limits<tppl_float>::min();
	tppl_float ymin = std::numeric_limits<tppl_float>::max();
	tppl_float ymax = std::numeric_limits<tppl_float>::min();
	for(int i=0;i<poly->GetNumPoints();i++) {
		if(poly->GetPoint(i).x < xmin) xmin = poly->GetPoint(i).x;
		if(poly->GetPoint(i).x > xmax) xmax = poly->GetPoint(i).x;
		if(poly->GetPoint(i).y < ymin) ymin = poly->GetPoint(i).y;
		if(poly->GetPoint(i).y > ymax) ymax = poly->GetPoint(i).y;
	}

	DrawPoly(&img, poly, xmin, xmax, ymin, ymax);

	io.SaveImage(filename,&img);
}
开发者ID:BackupGGCode,项目名称:polypartition,代码行数:21,代码来源:test.cpp

示例9: computePCImage

    RealImage::Pointer SIFTImagePCAComputer::computePCImage(SIFTImage* image, int k) {
        ImageIO<RealImage> io;
        RealImage::Pointer outputImg = io.NewImageT(image->GetBufferedRegion().GetSize());

        SIFTFeature* feature = image->GetBufferPointer();
        DataReal* output = outputImg->GetBufferPointer();
        const uint size = image->GetPixelContainer()->Size();
        const uint featureSize = feature[0].GetNumberOfComponents();
        for (uint i = 0; i < size; i++) {
            uchar* data = feature->GetDataPointer();
            float sum = 0;
            for (uint j = 0; j < featureSize; j++) {
                sum += this->V[j][featureSize - 1 - k] * data[j];
            }
            *output = std::abs(sum);

            output++;
            feature++;
        }
        return outputImg;
    }
开发者ID:fayhot,项目名称:gradworks,代码行数:21,代码来源:itkSIFTImageFilter.cpp

示例10: Assert

int EMUtil::get_image_count(const string & filename)
{
	ENTERFUNC;

	Assert(filename != "");

	int nimg = 0;

	ImageIO *imageio = get_imageio(filename, ImageIO::READ_ONLY);

	if (imageio) {
		nimg = imageio->get_nimg();
	}

   EMUtil::close_imageio(filename, imageio);

	imageio = NULL;

	EXITFUNC;

	return nimg;
}
开发者ID:jgalaz84,项目名称:eman2,代码行数:22,代码来源:emutil.cpp

示例11: runPointMarks

/// create a new image which has the same attributes with the reference image
///
int runPointMarks(pi::Options& opts, pi::StringVector& args) {
    vtkPolyDataReader* reader = vtkPolyDataReader::New();
    reader->SetFileName(args[0].c_str());
    reader->Update();

    vtkPolyData*pd = reader->GetOutput();

    // load an image
    ImageIO<RealImage> imageIO;
    RealImage::Pointer refImage = imageIO.ReadImage(args[1].c_str());


    // create an empty image
    ImageIO<LabelImage> labelIO;
    LabelImage::Pointer markImage = labelIO.NewImageS<RealImage>(refImage);
    markImage->FillBuffer(0);

    // point flipping
    for (int i = 0; i < pd->GetNumberOfPoints(); i++) {
        RealImage::PointType p;
        pd->GetPoint(i, p.GetDataPointer());
        p[0] = -p[0];
        p[1] = -p[1];
        pd->GetPoints()->SetPoint(i, p.GetDataPointer());

        // point to index
        RealImage::IndexType idx;
        refImage->TransformPhysicalPointToIndex(p, idx);

        // mark image
        markImage->SetPixel(idx, 255);
    }

    labelIO.WriteImage(args[2], markImage);
    return EXIT_SUCCESS;
}
开发者ID:fayhot,项目名称:gradworks,代码行数:38,代码来源:kvoxelizer.cpp

示例12: printf

void ObjMeshRender::Texture::loadTextureImage(string fullPath, int * width, int * height, int * bpp, unsigned char ** texData)
{
  ImageIO imageIO;
  ImageIO::fileFormatType fileFormat;
  // automatically determines the file format type from the filename extension; see imageIO class
  ImageIO::errorType errorCode = imageIO.load(fullPath.c_str(), &fileFormat);
  if (errorCode != ImageIO::OK)
  {
    printf("Warning: unable to load texture %s.\n", fullPath.c_str());
    return;
  }

  *width = imageIO.getWidth();
  *height = imageIO.getHeight();
  *bpp = imageIO.getBytesPerPixel();
  *texData = (unsigned char*) malloc (sizeof(unsigned char) * *width * *height * *bpp);
  memcpy(*texData, imageIO.getPixels(), sizeof(unsigned char) * *width * *height * *bpp);
}
开发者ID:yajunyang,项目名称:QtBullet,代码行数:18,代码来源:objMeshRender.cpp

示例13: load

void Image::load(const std::string& filename)
{
    ImageIO iio;
    iio.load(*this, filename);
}
开发者ID:hattorishizuko,项目名称:choreonoid,代码行数:5,代码来源:Image.cpp

示例14: read_binedimage

void EMData::read_binedimage(const string & filename, int img_index, int binfactor, bool fast, bool is_3d)
{
	ENTERFUNC;
	
	ImageIO *imageio = EMUtil::get_imageio(filename, ImageIO::READ_ONLY);
	
	if (!imageio) {
		throw ImageFormatException("cannot create an image io");
	}
	else {
		int err = imageio->read_header(attr_dict, img_index, 0, is_3d);
		if (err) {
			throw ImageReadException(filename, "imageio read header failed");
		}
		else {
			attr_dict["source_path"] = filename;
			attr_dict["source_n"] = img_index;
			if (imageio->is_complex_mode()) {
				set_complex(true);
				set_fftpad(true);
			}
			if (attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1) {
				set_fftodd(true);
			}
			if ((int) attr_dict["is_complex_ri"] == 1) {
				set_ri(true);
			}
			save_byteorder_to_dict(imageio);

			int ori_nx = nx = attr_dict["nx"];
			int ori_ny = ny = attr_dict["ny"];
			int ori_nz = nz = attr_dict["nz"];
			attr_dict.erase("nx");
			attr_dict.erase("ny");
			attr_dict.erase("nz");
			
			// At this point nx, ny and nz are all reduced by binfactor
			set_size(nx/binfactor, ny/binfactor, nz/binfactor);

			//here is where we read in the binned data
			EMData* tempdata = new EMData();
			size_t sizeofslice = nx*ny*sizeof(float);
			
			//zbin factor use 1 to speed binning(but don't benfit by averaging in Z)
			int zbin = binfactor;
			if(fast) zbin = 1;
			//verbose
			float percent = 0.1f;
			for(int k = 0; k < ori_nz; k+=binfactor){
				if(k > ori_nz*percent){	
					cout << float(k)/float(ori_nz) << "% Done!" << endl;
					percent+=0.1f;
				}
				// read in a slice region
				const Region* binregion = new Region(0,0,k,ori_nx,ori_ny,zbin);
				tempdata->read_image(filename, 0, false, binregion);
				// shrink the slice
				if (binfactor > 1) tempdata->process_inplace("math.meanshrink",Dict("n",binfactor));
				size_t offset = nx*ny*k/binfactor;
				//add slice to total
				EMUtil::em_memcpy(get_data()+offset,tempdata->get_data(),sizeofslice);
				delete binregion;
			}
			
			delete tempdata;
			update();
		}
	}

#ifndef IMAGEIO_CACHE
	if( imageio )
	{
#ifdef HDFIO_CACHE
		if(dynamic_cast<HdfIO2*>(imageio)==NULL && dynamic_cast<HdfIO*>(imageio)==NULL) {
#endif	//HDFIO_CACHE
			delete imageio;
			imageio = 0;
#ifdef HDFIO_CACHE
		}
#endif	//HDFIO_CACHE
	}
#endif	//IMAGEIO_CACHE

	EXITFUNC;
}
开发者ID:C-CINA,项目名称:2dx,代码行数:85,代码来源:emdata_io.cpp

示例15: fft_shuffle

void EMData::write_image(const string & filename, int img_index,
						 EMUtil::ImageType imgtype,
						 bool header_only, const Region * region,
						 EMUtil::EMDataType filestoragetype,
						 bool use_host_endian)
{
	ENTERFUNC;

	struct stat fileinfo;
	if ( region && stat(filename.c_str(),&fileinfo) != 0 ) throw UnexpectedBehaviorException("To write an image using a region the file must already exist and be the correct dimensions");

	if (is_complex() && is_shuffled())
		fft_shuffle();

	if (imgtype == EMUtil::IMAGE_UNKNOWN) {
		const char *ext = strrchr(filename.c_str(), '.');
		if (ext) {
			ext++;
			imgtype = EMUtil::get_image_ext_type(ext);
		}
	}
	ImageIO::IOMode rwmode = ImageIO::READ_WRITE;

	//set "nx", "ny", "nz" and "changecount" in attr_dict, since they are taken out of attribute dictionary
	attr_dict["nx"] = nx;
	attr_dict["ny"] = ny;
	attr_dict["nz"] = nz;
	attr_dict["changecount"] = changecount;

#ifndef HDFIO_CACHE
	if (Util::is_file_exist(filename)) {
		LOGVAR("file exists");
		if (!header_only && region == 0) {
			ImageIO * tmp_imageio = EMUtil::get_imageio(filename, ImageIO::READ_ONLY,
														imgtype);
			if (tmp_imageio->is_single_image_format()) {
				rwmode = ImageIO::WRITE_ONLY;
			}

#ifndef IMAGEIO_CACHE
			if( tmp_imageio )
			{
				delete tmp_imageio;
				tmp_imageio = 0;
			}
#endif	//IMAGEIO_CACHE
		}
	}
#endif	//HDFIO_CACHE

	LOGVAR("getimageio %d",rwmode);
	ImageIO *imageio = EMUtil::get_imageio(filename, rwmode, imgtype);
	if (!imageio) {
		throw ImageFormatException("cannot create an image io");
	}
	else {
		update_stat();
		/* Let each image format decide how to deal with negative image_index*/
//		if (img_index < 0) {
//			img_index = imageio->get_nimg();
//		}
		LOGVAR("header write %d",img_index);

		switch(filestoragetype) {
		case EMUtil::EM_UINT:
			attr_dict["datatype"] = (int)EMUtil::EM_UINT;
			break;
		case EMUtil::EM_USHORT:
			attr_dict["datatype"] = (int)EMUtil::EM_USHORT;
			break;
		case EMUtil::EM_SHORT:
			attr_dict["datatype"] = (int)EMUtil::EM_SHORT;
			break;
		case EMUtil::EM_CHAR:
			attr_dict["datatype"] = (int)EMUtil::EM_CHAR;
			break;
		case EMUtil::EM_UCHAR:
			attr_dict["datatype"] = (int)EMUtil::EM_UCHAR;
			break;
		default:
			attr_dict["datatype"] = (int)EMUtil::EM_FLOAT;;	//default float
		}

		int err = imageio->write_header(attr_dict, img_index, region, filestoragetype,
										use_host_endian);
		if (err) {
			throw ImageWriteException(filename, "imageio write header failed");
		}
		else {
			if (!header_only) {
				if (imgtype == EMUtil::IMAGE_LST) {
					const char *reffile = attr_dict["LST.reffile"];
					if (strcmp(reffile, "") == 0) {
						reffile = path.c_str();
					}
					int refn = attr_dict["LST.refn"];
					if (refn < 0) {
						refn = pathnum;
					}

//.........这里部分代码省略.........
开发者ID:C-CINA,项目名称:2dx,代码行数:101,代码来源:emdata_io.cpp


注:本文中的ImageIO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。