Example #1
0
// "readHeader()": read nifti header information from file
nifti_1_header niftiManager::readHeader( const std::string& imageFilenameRef ) const
{
    std::string imageFilenameZipped( imageFilenameRef );
    std::string imageFilename( imageFilenameRef );

    std::string extension( boost::filesystem::path(imageFilename).extension().string() );


    if ( extension == ".gz" )
    {
        imageFilename.resize(imageFilename.size()-3);

        // Variables for calling system commands
        std::string sysCommand( "gzip -dcf " + imageFilenameZipped + " > " + imageFilename );
        int success(system(sysCommand.c_str()));
    }
    else if ( extension == getFileExtension( ETFull ) )
    {
    }
    else
    {
        std::cerr << "File \"" << imageFilenameZipped << "\" has no recognized extension (\"" << extension << "\") stopping." << std::endl;
        exit(1);
    }

    nifti_image*  niftiImage = NULL;

    boost::mutex& ioMutex(boost::detail::thread::singleton<boost::mutex>::instance()) ;
    ioMutex.lock();
    {
        niftiImage = nifti_image_read(imageFilename.c_str(), 0);  // load_data = 0, only header and not image data is read
    }
    ioMutex.unlock();

    if( !niftiImage )
    {
        std::stringstream errormessage;
        errormessage << "ERROR @ niftiManager::readHeader(): there was an error calling nifti_image_read() on image file "<< imageFilename <<std::endl;
        throw std::runtime_error(  errormessage.str() );
    }

    if( niftiImage->ndim > 3 )
    {
        std::stringstream errormessage;
        errormessage << "ERROR @ niftiManager::readHeader(): nifti file has more than 3 dimensions (" << niftiImage->ndim <<"): "<< niftiImage->nx <<" "<< niftiImage->ny <<" "<< niftiImage->nz <<" "<< niftiImage->nt <<" "<< niftiImage->nu <<" "<< niftiImage->nv <<std::endl;
        throw std::runtime_error(  errormessage.str() );
    }

    nifti_1_header header = nifti_convert_nim2nhdr( niftiImage );
    // clean up
    nifti_image_free( niftiImage );

    if ( extension == ".gz" )
    {
        // Variables for calling system commands
        std::string sysCommand( "rm -f " + imageFilename );
        int success(system(sysCommand.c_str()));
    }
    return header;
}// end niftiManager::readHeader() -----------------------------------------------------------------
void ImageViewer::showImage()
{
    QString imageFilename( "chained view from app 1" );
    QStringList list;
    list << imageFilename;

    if ( chainingExampleInterface->isValid() ) {
        chainingExampleInterface->showImage( imageFilename, list, "title from app1" );
    } else {
        qDebug() << "chainingExampleInterface not valid : " << chainingExampleInterface;
    }
}
Example #3
0
int main(int argc, char* argv[])
{
	QApplication app(argc, argv);

	const std::string outputFileName = "out_test.png";
	QImage outputImage;
	std::pair<std::string, std::string> imageFilename("../../data/pier/1.jpg", "../../data/pier/2.jpg");
	std::pair<QImage, QImage> image;
	if (!image.first.load(imageFilename.first.c_str()))
	{
		std::cerr << "[Error] Could not load image filr: " << imageFilename.first << std::endl;
		return EXIT_FAILURE;
	}

	if (!image.second.load(imageFilename.second.c_str()))
	{
		std::cerr << "[Error] Could not load image filr: " << imageFilename.second << std::endl;
		return EXIT_FAILURE;
	}


	DLT dlt;
	dlt.addPoint(std::make_pair(Eigen::Vector2d(370.361, 198.972), Eigen::Vector2d(81.6814, 171.918)));
	dlt.addPoint(std::make_pair(Eigen::Vector2d(378.627, 206.653), Eigen::Vector2d(89.9805, 179.755)));
	dlt.addPoint(std::make_pair(Eigen::Vector2d(413.459, 214.739), Eigen::Vector2d(124.377, 188.050)));
	dlt.addPoint(std::make_pair(Eigen::Vector2d(407.815, 209.960), Eigen::Vector2d(118.867, 183.199)));


	Eigen::MatrixXd H = dlt.computeHomography();
	//std::cout << "H = \n" << H << std::endl << std::endl;
	
	projectImages(H, image, outputImage);
	outputImage.save("test_out_H.png");

	double sum_error = GaussNewton::getSumError(dlt.getPoints(), H);
	std::cout << "\nDLT H sum_error: " << sum_error << std::endl << std::endl << std::endl;

	std::vector<std::pair<Eigen::Vector2d, Eigen::Vector2d>> hp;
	Points::projectPoints(dlt.getPoints(), hp, H);

	//for (int i = 0; i < hp.size(); ++i)
	//{
	//	std::cout << dlt.getPoints()[i].first.transpose() << "  " << hp[i].first.transpose() << "   "
	//		<< dlt.getPoints()[i].second.transpose() << "  " << hp[i].second.transpose() << std::endl;
	//}

	H(0, 2) += 0.1;
	H(1, 2) += -0.1;

	//std::cout << "\ndisturbed H = \n" << H << std::endl << std::endl;
	sum_error = GaussNewton::getSumError(dlt.getPoints(), H);
	std::cout << "\nH disturbed sum_error: " << sum_error << std::endl << std::endl << std::endl;

	projectImages(H, image, outputImage);
	outputImage.save("out_H_disturbed.png");
	//return 0;

	Points::projectPoints(dlt.getPoints(), hp, H);
	//for (int i = 0; i < hp.size(); ++i)
	//{
	//	std::cout << dlt.getPoints()[i].first.transpose() << "  " << hp[i].first.transpose() << "   "
	//		<< dlt.getPoints()[i].second.transpose() << "  " << hp[i].second.transpose() << std::endl;
	//}



	//projectImages(H, image, outputImage);
	//outputImage.save("out_H_Jacobian.png");
	//sum_error = getSumError(dlt.getPoints(), H);
	//std::cout << "\Jacobian H sum_error: " << sum_error << std::endl;
	//return 0;



	const int maxIt = 1;
	bool error_maximized = false;

	//for (int it = 0; it < 3; ++it)
	int it = 0;
	while (it++ < maxIt && !error_maximized)
	{
		std::cout << "\n\n-------- begin loop ------  " << it - 1 << std::endl << std::endl;

		Eigen::MatrixXd dH = GaussNewton::computeDeltaH(dlt.getPoints(), H);

		H = H + dH;

		std::cout << "H = \n" << H << std::endl << std::endl;

		Points::projectPoints(dlt.getPoints(), hp, H);
		double new_sum_error = GaussNewton::getSumError(dlt.getPoints(), hp);

		if (sum_error > new_sum_error)
		{
			std::cout << std::fixed << "\n ** error minimized    : " << sum_error << " -> " << new_sum_error << std::endl;
			sum_error = new_sum_error;
		}
		else
		{
			std::cout << std::fixed << "\n ** error maximized    : " << sum_error << " -> " << new_sum_error << std::endl;
			error_maximized = true;
		}

		std::cout << "-------------- end loop ----------------------" << std::endl << std::endl;

		//if (!error_maximized)
		//{
		//	projectImages(H, image, outputImage);
		//	QString filename("out_H_" + QString::number(it) + ".png");
		//	outputImage.save(filename);
		//}

	}




	//projectImages(H, image, outputImage);
	////outputImage.save(outputFileName.c_str());
	//outputImage.save("out_H.png");


	//projectImages(HJ, image, outputImage);
	////outputImage.save(outputFileName.c_str());
	//outputImage.save("out_HJ.png");



	

	//QImageWidget outputWidget;
	//outputWidget.setImage(outputImage);
	//outputWidget.show();

	std::cout << "\n************** // ********************\n";

	return 0;
	//return app.exec();
}
Example #4
0
int QTweetStatusUpdateWithMedia::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTweetNetBase::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 2)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 2;
    } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
        if (_id < 2)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = status(); break;
        case 1: *reinterpret_cast< QString*>(_v) = imageFilename(); break;
        case 2: *reinterpret_cast< bool*>(_v) = isSensitive(); break;
        case 3: *reinterpret_cast< qint64*>(_v) = inReplyToStatusID(); break;
        case 4: *reinterpret_cast< double*>(_v) = latitude(); break;
        case 5: *reinterpret_cast< double*>(_v) = longitude(); break;
        case 6: *reinterpret_cast< QString*>(_v) = placeID(); break;
        case 7: *reinterpret_cast< bool*>(_v) = displayCoordinates(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setStatus(*reinterpret_cast< QString*>(_v)); break;
        case 1: setImageFilename(*reinterpret_cast< QString*>(_v)); break;
        case 2: setSensitive(*reinterpret_cast< bool*>(_v)); break;
        case 3: setReplyToStatusID(*reinterpret_cast< qint64*>(_v)); break;
        case 4: setLatitude(*reinterpret_cast< double*>(_v)); break;
        case 5: setLongitude(*reinterpret_cast< double*>(_v)); break;
        case 6: setPlaceID(*reinterpret_cast< QString*>(_v)); break;
        case 7: setDisplayCoordinates(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    } else if (_c == QMetaObject::RegisterPropertyMetaType) {
        if (_id < 8)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #5
0
bool K3bCueFileParser::findImageFileName( const QString& dataFile )
{
  //
  // CDRDAO does not use this image filename but replaces the extension from the cue file
  // with "bin" to get the image filename, we should take this into account
  //

  m_imageFilenameInCue = true;

  // first try filename as a hole (absolut)
  if( QFile::exists( dataFile ) ) {
    setImageFilename( QFileInfo(dataFile).absFilePath() );
    return true;
  }

  // try the filename in the cue's directory
  if( QFileInfo( K3b::parentDir(filename()) + dataFile.section( '/', -1 ) ).isFile() ) {
    setImageFilename( K3b::parentDir(filename()) + dataFile.section( '/', -1 ) );
    kdDebug() << "(K3bCueFileParser) found image file: " << imageFilename() << endl;
    return true;
  }

  // try the filename ignoring case
  if( QFileInfo( K3b::parentDir(filename()) + dataFile.section( '/', -1 ).lower() ).isFile() ) {
    setImageFilename( K3b::parentDir(filename()) + dataFile.section( '/', -1 ).lower() );
    kdDebug() << "(K3bCueFileParser) found image file: " << imageFilename() << endl;
    return true;
  }

  m_imageFilenameInCue = false;

  // try removing the ending from the cue file (image.bin.cue and image.bin)
  if( QFileInfo( filename().left( filename().length()-4 ) ).isFile() ) {
    setImageFilename( filename().left( filename().length()-4 ) );
    kdDebug() << "(K3bCueFileParser) found image file: " << imageFilename() << endl;
    return true;
  }

  //
  // we did not find the image specified in the cue.
  // Search for another one having the same filename as the cue but a different extension
  //

  QDir parentDir( K3b::parentDir(filename()) );
  QString filenamePrefix = filename().section( '/', -1 );
  filenamePrefix.truncate( filenamePrefix.length() - 3 ); // remove cue extension
  kdDebug() << "(K3bCueFileParser) checking folder " << parentDir.path() << " for files: " << filenamePrefix << "*" << endl;

  //
  // we cannot use the nameFilter in QDir because of the spaces that may occur in filenames
  //
  QStringList possibleImageFiles = parentDir.entryList( QDir::Files );
  int cnt = 0;
  for( QStringList::const_iterator it = possibleImageFiles.constBegin(); it != possibleImageFiles.constEnd(); ++it ) {
    if( (*it).lower() == dataFile.section( '/', -1 ).lower() ||
	(*it).startsWith( filenamePrefix ) && !(*it).endsWith( "cue" ) ) {
      ++cnt;
      setImageFilename( K3b::parentDir(filename()) + *it );
    }
  }

  //
  // we only do this if there is one unique file which fits the requirements. 
  // Otherwise we cannot be certain to have the right file.
  //
  return ( cnt == 1 && QFileInfo( imageFilename() ).isFile() );
}
Example #6
0
// "readImage()": reads a 3D image
ValueType niftiManager::readImage( const std::string& imageFilenameRef, std::vector<std::vector<std::vector<float> > >* imagePointer ) const
{
    std::vector<std::vector<std::vector<float> > >& image( *imagePointer );
    std::string imageFilename( imageFilenameRef );
    std::string imageFilenameZipped( imageFilenameRef );

    std::string extension( boost::filesystem::path(imageFilename).extension().string() );


    if ( extension == ".gz" )
    {
        imageFilename.resize(imageFilename.size()-3);
        // Variables for calling system commands
        std::string sysCommand( "gzip -dcf " + imageFilenameZipped + " > " + imageFilename );
        int success(system(sysCommand.c_str()));
    }
    else if ( extension == getFileExtension( ETFull ) )
    {
    }
    else
    {
        std::cerr << "File \"" << imageFilenameZipped << "\" has no recognized extension (\"" << extension << "\") stopping." << std::endl;
        return VTError;
    }

    nifti_image*  niftiImage = NULL;

    boost::mutex& ioMutex(boost::detail::thread::singleton<boost::mutex>::instance()) ;
    ioMutex.lock();
    {
        niftiImage = nifti_image_read(imageFilename.c_str(), 1);
    }
    ioMutex.unlock();

    if( !niftiImage )
    {
        std::cerr<< "ERROR @ niftiManager::readImage(): there was an error calling nifti_image_read() on image file "<< imageFilename <<std::endl;
        return VTError;
    }

    if( niftiImage->ndim > 3 )
    {
        std::cerr << "ERROR @ niftiManager::readImage(): nifti file has more than 3 dimensions (" << niftiImage->ndim <<"): "<< niftiImage->nx <<" "<< niftiImage->ny <<" "<< niftiImage->nz <<" "<< niftiImage->nt <<" "<< niftiImage->nu <<" "<< niftiImage->nv <<std::endl;
        return VTError;
    }
    const size_t repType( niftiImage->datatype );
    const size_t repByteSize( niftiImage->nbyper );
    const size_t dataSize( niftiImage->nvox );

    ValueType imageValueType;

    if(repType == DT_UINT8 )
    {
        imageValueType = VTUINT8;
    }
    else if(repType == DT_FLOAT32 )
    {
        imageValueType = VTFloat32;
    }
    else
    {
        std::cerr<< "ERROR @ niftiManager::readImage(): image representation type not recognized (neither UINT8 nor FLOAT32)" << std::endl;
        return VTError;
    }

    const size_t dimx( niftiImage->nx );
    const size_t dimy( niftiImage->ny );
    const size_t dimz( niftiImage->nz);

    image.clear();
    {
        std::vector<float> zvector(dimz,0);
        std::vector<std::vector<float> >yzmatrix(dimy,zvector);
        image.resize(dimx,yzmatrix);
    }
    void* niftiData(niftiImage->data);

    for (int i=0 ; i<dimz ; ++i)
    {
        for (int j=0 ; j<dimy ; ++j)
        {
            for (int k=0 ; k<dimx ; ++k)
            {
                size_t voxOffset( (i*dimy*dimx) + (j*dimx) + k );
                if( voxOffset >= dataSize )
                {
                    std::cerr<< "ERROR @ niftiManager::readImage():: pointer offset was too high when loading nifti data" << std::endl;
                    return VTError;
                }
                size_t byteOffset( voxOffset * repByteSize );
                void* dataPos = static_cast<unsigned char*>(niftiData) + byteOffset;

                if (repType == DT_UINT8)
                {
                    unsigned char datapoint = *(static_cast<unsigned char*>(dataPos));
                    image[k][j][i] = (float)datapoint;
                }
                else if (repType == DT_FLOAT32)
                {
                    float datapoint = *(static_cast<float*>(dataPos));
                    image[k][j][i] = datapoint;
                }
                else
                {
                    std::cerr<< "ERROR @ niftiManager::readImage(): image representation type not recognized (neither UINT8 nor FLOAT32)" << std::endl;
                    return VTError;
                }
            }
        }
    }
    // clean up
    nifti_image_free( niftiImage );

    if ( extension == ".gz" )
    {
        // Variables for calling system commands
        std::string sysCommand( "rm -f " + imageFilename );
        int success(system(sysCommand.c_str()));
    }
    return imageValueType;
}// end niftiManager::readImage() -----------------------------------------------------------------