コード例 #1
0
stereoview::image_id_type stereoview::add_image(const image_type& img, const option<float>& focal_length)
{
    if (!stored_image_db.empty() && (img.width() != width() || img.height() != height()))
        throw localized_invalid_argument(HERE(nfmt<4>("image size is %1 x %2 while expected size is %3 x %4") (img.width()) (img.height()) (width()) (height())));
    const unsigned int id = fresh_int();
    add_stored_image(id, img, focal_length);
    return id;
}
コード例 #2
0
IonDetector::result_type IonDetector::blob_detector( const image_type& img ) {
	Kernel logs[3];
	float sigmas[3];

	logs[0] = Kernel::LoG( 4, 0.6 );
	sigmas[0] = 0.85;

	logs[1] = Kernel::LoG( 6, 1.0 );
	sigmas[1] = 1.0;

	logs[2] = Kernel::LoG( 20, 5.0 );
	sigmas[2] = 2.;

	image_type img_result( img.extents );
	result_type results;

	const size_t hsize = 2000;
	std::vector< size_t > histogram( hsize, 0 );

	size_t g = 2;
	logs[g].apply_kernel( img, img_result );
	save_file( "log.fits", img_result );

	float img_max = *std::max_element( img_result.ptr(), 
		img_result.ptr() + img.num_elements() );
	for( 	float* iter = img_result.ptr(); 
			iter != img_result.ptr() + img.num_elements(); 
			++iter ) {

		int p = (size_t)( ( *iter + img_max ) / 2 / img_max * hsize ); 
		if( p >= (int)hsize ) 	p = hsize-1;
		if( p < 0 )				p = 0;
		histogram[ p ] ++;
	}

	size_t nelems = 0, counter = hsize-1;
	while( nelems < (size_t)blob_threshold )
		nelems += histogram[ counter-- ];

	float thresh = (float)counter / hsize * img_max - img_max / 2.;
	for( image_type::index i = 12; i < img.extents.first-12; ++i ) 
	for( image_type::index j = 12; j < img.extents.second-12; ++j ) {
		if( img_result( i, j ) > thresh &&
			img_result( i, j ) > img_result( i+1, j ) &&
			img_result( i, j ) > img_result( i-1, j ) &&
			img_result( i, j ) > img_result( i, j+1 ) &&
			img_result( i, j ) > img_result( i, j-1 ) &&
			img_result( i, j ) > img_result( i+1, j+1 ) &&
			img_result( i, j ) > img_result( i+1, j-1 ) &&
			img_result( i, j ) > img_result( i-1, j+1 ) &&
			img_result( i, j ) > img_result( i-1, j-1 ) ) {

			results.push_back( IonData( i, j, sigmas[g] ) );
		}
	}

	return results;
}
コード例 #3
0
ファイル: renderer.hpp プロジェクト: mapycz/mapnik
 unsigned compare(image_type const & actual, boost::filesystem::path const& reference) const
 {
     std::ifstream stream(reference.string().c_str(), std::ios_base::in | std::ios_base::binary);
     if (!stream)
     {
         throw std::runtime_error("Could not open: " + reference.string());
     }
     std::string expected(std::istreambuf_iterator<char>(stream.rdbuf()), std::istreambuf_iterator<char>());
     return std::max(actual.size(), expected.size()) - std::min(actual.size(), expected.size());
 }
コード例 #4
0
ファイル: region_growing.cpp プロジェクト: ChenglongWang/MIST
	TestRegionGrowing( ) : image( 10, 10 )
	{
		for( size_type j = 1 ; j < image.height( ) - 1 ; j++ )
		{
			for( size_type i = 1 ; i < image.width( ) - 1 ; i++ )
			{
				image( i, j ) = 1;
			}
		}
	}
コード例 #5
0
void fft_round_up(image_type& I,pos_type& from,pos_type& to)
{
    image_type newI(fft_round_up_geometry(I.geometry()));
    for(int dim = 0;dim < image_type::dimension;++dim)
    {
        from[dim] = (newI.geometry()[dim]-I.geometry()[dim]) >> 1;
        to[dim] = from[dim] + I.geometry()[dim];
    }
    image::draw(I,newI,from);
    I.swap(newI);
}
コード例 #6
0
ファイル: im_interface.cpp プロジェクト: ch3n2k/rss
void Image2DIB(const image_type &image, BYTE *dib)
{
	using namespace rss;
	const int all_header_size = 14 + 40 +1024;
	size_t dib_size = all_header_size 
		+ ( image.width() + ( (image.width()%4)?(4-image.width()%4):0) )* image.height();	
	
	std::ostrstream output(reinterpret_cast<char *>(dib), dib_size);
	BMPImageIO<image_type> image_io;
	if(!image_io.write(output, image))
		throw rss::Exception("library can not write this dib");
}
コード例 #7
0
IonDetector::result_type IonDetector::hough_transform( image_type& edges ) {
	const unsigned short num_radii = 4;

	std::vector< unsigned short > hough( 
		edges.num_elements()*num_radii, 0 );

	for( size_t r = 2; r < 6; ++r ) 
	for( image_type::index i = r+1; i<edges.extents.first-r-1; ++i ) 
	for( image_type::index j = r+1; j<edges.extents.second-r-1; ++j ) {
		if( edges( i, j ) ) {
			for( float theta = 0.; theta < 6.3; theta += 1. / r ) {
				size_t x = (size_t)( i + (float)r*cos( theta ) + 0.5f);
				size_t y = (size_t)( j + (float)r*sin( theta ) + 0.5f);
				hough[ (r-2)*edges.num_elements() +
					y*edges.extents.first + x ]++;
			}
		}
	}
		
	result_type results;
	for( size_t r = 5; r >= 2; --r )
	for( image_type::index i = 8; i < edges.extents.first-8; ++i ) 
	for( image_type::index j = 8; j < edges.extents.second-8; ++j ) {
		size_t index = (r-2)*edges.num_elements() + 
			j*edges.extents.first + i;
		const unsigned short value = hough[index];
		if( value > (size_t)(hough_threshold * r) ) {
			size_t h = 0;
			for( ;  h < results.size(); ++h ) {
				size_t xsq = (i - results[h].x)*(i - results[h].x);
				size_t ysq = (j - results[h].y)*(j - results[h].y);
				if( xsq + ysq < 36 ) break;
			}
			
			if( h != results.size() ) continue;
			if( hough[index + edges.extents.first] > value ) continue;
			if( hough[index - edges.extents.first] > value ) continue;
			if( hough[index - 1] > value ) continue;
			if( hough[index + 1] > value ) continue;

			results.push_back( IonData( i, j, r ) );
			std::cout<< "Circle " << i << " " << j << " " << r << std::endl;
			std::cout<< value << std::endl;
		}
	}
	
	return results;
}
コード例 #8
0
ファイル: renderer.hpp プロジェクト: mapycz/mapnik
    void convert(mapnik::grid::data_type const & grid, image_type & image) const
    {
        for (std::size_t y = 0; y < grid.height(); ++y)
        {
            mapnik::grid::value_type const * grid_row = grid.get_row(y);
            image_type::pixel_type * image_row = image.get_row(y);
            for (std::size_t x = 0; x < grid.width(); ++x)
            {
                mapnik::grid::value_type val = grid_row[x];

                if (val == mapnik::grid::base_mask)
                {
                    image_row[x] = 0;
                    continue;
                }
                if (val < 0)
                {
                    throw std::runtime_error("grid renderer: feature id is negative.");
                }

                val *= 100;

                if (val > 0x00ffffff)
                {
                    throw std::runtime_error("grid renderer: feature id is too high.");
                }

                image_row[x] = val | 0xff000000;
            }
        }
    }
コード例 #9
0
ファイル: im_interface.cpp プロジェクト: ch3n2k/rss
void RSS_MultiSensor_PCA_Fusion(const image_type &image1, const image_type &image2, image_type &result)
{
	using namespace rss;
	rss::ImageVector<image_type> input_vector;
	input_vector.push_back(image1);
	if(image1.size() != image2.size()) {
		BilinearInterpolation<image_type> interpolate(image1.size());
		image_type temp;
		interpolate(image2, temp);
		input_vector.push_back(temp);
	} else { 
		input_vector.push_back(image2);
	}

	PCAFusion<image_type> fusion(image1.width(), image1.height());
	fusion(input_vector, result);		
}
コード例 #10
0
ファイル: im_interface.cpp プロジェクト: ch3n2k/rss
void RSS_MultiSensor_Wavelet_Fusion(const image_type &image1, const image_type &image2, image_type &result)
{
	using namespace rss;
	rss::ImageVector<image_type> input_vector;
	input_vector.push_back(image1);
	if(image1.size() != image2.size()) {
		BilinearInterpolation<image_type> interpolate(image1.size());
		image_type result;
		interpolate(image2, result);
		input_vector.push_back(result);
	} else { 
		input_vector.push_back(image2);
	}

	WaveletFusion<image_type> fusion(image1.size(), FilterSet::Haar());
	fusion(input_vector, result);		

}
コード例 #11
0
ファイル: im_interface.cpp プロジェクト: ch3n2k/rss
void RSS_MultiSensor_Contour_Register(const image_type &VLImage, const image_type &IRImage, float para[6], image_type &result)
{
	using namespace rss;
	ContourRegister contour_register(HomoModel::Similarity, 3.1, 0.0, 0.0, 0.0, 30, 0.18, 0.8, 0.5);
	HomoModel model; 
	contour_register(VLImage, IRImage,model);
	HomoTrans<image_type> homo_trans(model, VLImage.size());
	homo_trans.inverse(IRImage, result);
}
コード例 #12
0
void fft_shift_x(image_type& I)
{
    int half_w = I.width() >> 1;
    int half_w_1 = half_w-1;
    int w_1 = I.width()-1;
    int quater_w = half_w >> 1;
    typename image_type::iterator iter1 = I.begin();
    typename image_type::iterator end = I.end();
    for(;iter1 != end;iter1 += I.width())
    {
        typename image_type::iterator iter2 = iter1+half_w;
        for(int x = 0,rx = half_w_1;x < quater_w;++x,--rx)
        {
            std::swap(iter1[x],iter1[rx]);
            std::swap(iter2[x],iter2[rx]);
        }
    }
}
コード例 #13
0
void fft_shift_z(image_type& I)
{
    int wh = I.plane_size();
    int half_size = I.size() >> 1;
    int half_size_1 = half_size-wh;
    int quater_size = half_size >> 1;
    typename image_type::iterator iter1 = I.begin();
    typename image_type::iterator iter2 = iter1+half_size;
    typename image_type::iterator end = iter1+wh;
    for(;iter1 != end;++iter1,++iter2)
    {
        for(int z = 0,rz = half_size_1;z < quater_size;z+=wh,rz-=wh)
        {
            std::swap(iter1[z],iter1[rz]);
            std::swap(iter2[z],iter2[rz]);
        }
    }
}
コード例 #14
0
ファイル: renderer.hpp プロジェクト: gischen/mapnik
 unsigned compare(image_type const & actual, boost::filesystem::path const& reference) const
 {
     std::ifstream stream(reference.string().c_str(),std::ios_base::in|std::ios_base::binary);
     if (!stream.is_open())
     {
         throw std::runtime_error("could not open: '" + reference.string() + "'");
     }
     std::string expected(std::istreambuf_iterator<char>(stream.rdbuf()),(std::istreambuf_iterator<char>()));
     stream.close();
     return std::fabs(actual.size() - expected.size());
 }
コード例 #15
0
void decode_image_impl(image_type& image) {
  if (image.m_format == Format::RAW_ARRAY) {
    return;
  }

  char* buf = NULL;
  size_t length = 0;

  if (image.m_format == Format::JPG) {
    decode_jpeg((const char*)image.get_image_data(), image.m_image_data_size,
                &buf, length);
  } else if (image.m_format == Format::PNG) {
    decode_png((const char*)image.get_image_data(), image.m_image_data_size,
                &buf, length);
  } else {
    log_and_throw(std::string("Cannot decode image. Unknown format."));
  };
  image.m_image_data.reset(buf);
  image.m_image_data_size = length;
  image.m_format = Format::RAW_ARRAY;
}
コード例 #16
0
void save_file( const std::string& filename, const image_type& img ) {
	fitsfile* f;
	int status = 0;

    std::string fname = "!" + filename;
	fits_create_file( &f, fname.c_str(), &status );
	
	long dims[2];
	dims[0] = img.extents.first;	dims[1] = img.extents.second;

	typedef CFitsIOTypeMap<	image_type::element > map;
	fits_create_img( f, map::image_type, 2, dims, &status );
	fits_write_img( f, map::type, 1, img.num_elements(), 
		(void*)img.ptr(), &status );
        
    fits_close_file( f, &status );

	if( status ) {
		fits_report_error( stderr, status );
	}
}
コード例 #17
0
void fft_shift_y(image_type& I)
{
    int w = I.width();
    int half_wh = I.plane_size() >> 1;
    int half_wh_1 = half_wh-w;
    int quater_wh = half_wh >> 1;
    typename image_type::iterator iter1 = I.begin();
    typename image_type::iterator end = I.end();
    for(;iter1 != end;iter1 += I.plane_size())
    {
        typename image_type::iterator iter1_x = iter1;
        typename image_type::iterator iter1_x_end = iter1+w;
        typename image_type::iterator iter2_x = iter1_x+half_wh;
        for(;iter1_x != iter1_x_end;++iter1_x,++iter2_x)
        for(int y = 0,ry = half_wh_1;y < quater_wh;y+=w,ry-=w)
        {
            std::swap(iter1_x[y],iter1_x[ry]);
            std::swap(iter2_x[y],iter2_x[ry]);
        }
    }
}
コード例 #18
0
void encode_image_impl(image_type& image) {
  if (image.m_format != Format::RAW_ARRAY){
    return;
  } 

  char* buf = NULL;
  size_t length = 0;

  encode_png((const char*)image.get_image_data(), image.m_width, image.m_height, image.m_channels, &buf, length);
  image.m_image_data.reset(buf);
  image.m_image_data_size = length;
  image.m_format = Format::PNG;
}
コード例 #19
0
    inline void load (
        const image_type& img
    )
    {
        feat_image.set_size(img.nr(), img.nc());
        assign_all_pixels(feat_image,0);
        for (long r = 1; r+1 < img.nr(); ++r)
        {
            for (long c = 1; c+1 < img.nc(); ++c)
            {
                unsigned char f = 0;
                if (img[r][c])   f |= 0x1;
                if (img[r][c+1]) f |= 0x2;
                if (img[r][c-1]) f |= 0x4;
                if (img[r+1][c]) f |= 0x8;
                if (img[r-1][c]) f |= 0x10;

                // Store the code value for the pattern of pixel values in the 4-connected
                // neighborhood around this row and column.
                feat_image[r][c] = f;
            }
        }
    }
コード例 #20
0
ファイル: gradient_magnitude.hpp プロジェクト: frankyeh/TIPL
    void operator()(image_type& src)
    {
        typedef tipl::image<typename image_type::value_type,image_type::dimension> image_buf_type;
        image_buf_type gx;
        gradient_2x(src,gx);

        image_buf_type gy;
        gradient_2y(src,gy);

        for(size_t index = 0;index < src.size();++index)
        {
            float fx = gx[index];
            float fy = gy[index];
            src[index] = std::sqrt(fx*fx+fy*fy);
        }
    }
コード例 #21
0
ファイル: im_interface.cpp プロジェクト: ch3n2k/rss
void RSS_MultiSensor_FFT_Register(const image_type &VLImage, const image_type &IRImage, float para[6], image_type &result)
{
	using namespace rss;
	image_type temp;
	if(para) {
		double scale1 = para[0] / para[3] * para[4] / para[1] * VLImage.width() / IRImage.width();
		double scale2 = para[0] / para[3] * para[5] / para[2] * VLImage.height() / IRImage.height();
		double scale = sqrt(scale1*scale2);

		HomoModel pre_trans_model;
		pre_trans_model.SetSimilarity(scale, 0, IRImage.width() * (1 - scale) / 2.0, IRImage.height() * (1 - scale) / 2.0);
		HomoTrans<image_type> pre_trans(pre_trans_model, VLImage.size());
		pre_trans.operator ()(IRImage, temp);
	} else {
		temp = IRImage;
	}
	HomoModel model;
	SimilarityEstimation(true, true, false, SimilarityEstimation::OP_NONE, SimilarityEstimation::FILTER_NONE)(VLImage, temp, model);
	HomoTrans<image_type> homo_trans(model, VLImage.size());
	homo_trans.operator()(temp, result);

}
コード例 #22
0
ファイル: im_interface.cpp プロジェクト: ch3n2k/rss
void RSS_MultiSensor_Fleet_Region(const image_type &VLImage, const image_type &IRImage, image_type &result1, image_type &result2, float regions[61])
{
	using namespace rss;
	rss::FleetEdgeDetector detector;
	detector(IRImage, result1);
	// result1 holds the fution image
	RSS_MultiSensor_Wavelet_Fusion(VLImage,IRImage,result1);

	// put the image of result into the Memeory dc
	HDC m_hDC = CreateCompatibleDC(::GetDC(NULL));
	HBITMAP m_hBitmap = CreateCompatibleBitmap(::GetDC(NULL),result1.width(),result1.height());
	HPEN m_hPen = CreatePen(PS_SOLID,1,RGB(255,255,255));
	HBRUSH m_hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
	SelectObject(m_hDC,m_hBitmap);
	SelectObject(m_hDC,m_hPen);
	SelectObject(m_hDC,m_hBrush);
	SetBkMode(m_hDC,TRANSPARENT);
	SetTextColor(m_hDC,RGB(255,255,255));
	for (int x = 0; x < result1.width(); x ++) {
		for (int y = 0; y < result1.height(); y ++) {
			int gray = rss::pixel_cast<rss::GrayPixel>(result1(x,y));
			COLORREF color = RGB(gray,gray,gray);
			SetPixel(m_hDC,x,y,color);
		}
	}

	ObjectiveRegions r = detector.objective_region();		
	regions[0] = min(20u, static_cast<float>(r.size()));		
	for(size_t i = 0; i < min(20U, r.size()); i++) {
		regions[i*3 + 1] = r[i].center.x();
		regions[i*3 + 2] = r[i].center.y();
		regions[i*3 + 3] = r[i].reliability;
	}
	// fill the background
	result2.resize(result1.size());
	for (int x = 0; x < result2.width(); x ++)
		for (int y =  0; y < result2.height(); y ++)
			result2(x,y) = 0;
	// file the sensitive region
	for (int i = 0; i < min(20U,r.size()); i ++) {
		::Rectangle(m_hDC,r[i].region.left(),r[i].region.top(),r[i].region.right(),r[i].region.bottom());
		int dx = (r[i].region.right() - r[i].region.left()) / 2;
		int dy = (r[i].region.bottom() - r[i].region.top()) / 2;
		char* str = RSS_MultiSensor_Get_String(i+1);
		TextOut(m_hDC,r[i].region.left()+dx,r[i].region.top()+dy,str,strlen(str));
		image_type region;
		region.resize(r[i].region.size());
		for (int x = r[i].region.left(); x < r[i].region.right(); x ++) {
			for (int y = r[i].region.top(); y < r[i].region.bottom(); y ++) {
				region(x-r[i].region.left(),y-r[i].region.top()) = VLImage(x,y);
			}
		}
		RegionGrow<image_type> regionGrow(1.0/5.0,10);
		image_type region_result;
		regionGrow(region,region_result);
		for (int x = r[i].region.left(); x < r[i].region.right(); x ++) {
			for (int y = r[i].region.top(); y < r[i].region.bottom(); y ++) {
				result2(x,y) = region_result(x-r[i].region.left(),y-r[i].region.top());
			}
		}
	}
	//	put the image of Memory dc back to result1
	for (int x = 0; x < VLImage.width(); x ++) {
		for (int y = 0; y < VLImage.height(); y ++) {
			result1(x,y) = rss::pixel_cast<rss::RealPixel>GetRValue(GetPixel(m_hDC,x,y));
		}
	}
	DeleteObject(m_hDC);
	DeleteObject(m_hBitmap);
	DeleteObject(m_hPen);
	DeleteObject(m_hBrush);

}
コード例 #23
0
void stereoview::stored_image::image_to_gray_raw(const image_type& img, unsigned char* raw)
{
    for (int y = 0; y < img.height(); ++y)
        for (int x = 0; x < img.width(); ++x)
            *raw++ = qGray(img.pixel(x, y));
}
コード例 #24
0
int main( int argc , char *argv[ ] )
{
	// 入力ボリュームデータの作成
	const vector_type c( ( va.width( ) - 1 ) / 2.0, ( va.height( ) - 1 ) / 2.0, ( va.depth( ) - 1 ) / 2.0 );
	vector_type c0( c ), c1( c );
	c0.x -= 8.0;
	c1.x += 8.0;
	for( size_t k = 0 ; k < va.depth( ) ; k ++ )
	{
		for( size_t j = 0 ; j < va.height( ) ; j ++ )
		{
			for( size_t i = 0 ; i < va.width( ) ; i ++ )
			{
				const vector_type p( static_cast< double >( i ), static_cast< double >( j ), static_cast< double >( k ) );
				const double d0 = distance( p, c0 );
				const double d1 = distance( p, c1 );
				va( i, j, k ) = 31.5 - minimum( d0, d1 );
				if( va( i, j, k ) < 0.0 )
				{
					va( i, j, k ) = 0.0;
				}
			}
		}
	}


	// 等値面生成の前処理(入力ボリュームデータを渡す)
	// 本サンプルのように描画の度に閾値を動的に変化させながら等値面生成を行う場合に生成処理時間を短縮できる
	// この行をコメントアウトしたものとしないものを比較すると処理速度の違いがわかる
	mcs.preprocess( va );
	
	// 等値面生成パラメータ設定	
	mcs.offset( -31.5, -15.5, -15.5 );
	mcs.scale( 0.1, 0.1, 0.1 );
	
	// 等値面生成結果格納のため,大きめの領域を確保しておくことで
	// ベクタの要素サイズの増加に伴うメモリ再確保の発生を抑制
	pv.reserve( 32768 );
	nv.reserve( 32768 );
	sv.reserve( 32768 );
	

	glutInit( &argc , argv );
	glutInitWindowPosition( 100 , 100 );
	glutInitWindowSize( 400 , 400 );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
	glutCreateWindow( "mist::marching_cubes" );
	glutDisplayFunc( disp );
	glutIdleFunc( idle );
	glMatrixMode( GL_PROJECTION );
	glFrustum( -1 , 1 , -1 , 1 , 1 , 5 );
	gluLookAt( 0.0, 0.0, 4.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 );
	GLfloat lpos[ ] = { 0 , 0 , 4 , 1 };
	glLightfv( GL_LIGHT0 , GL_POSITION , lpos );
	glEnable( GL_LIGHTING );
	glEnable( GL_LIGHT0 );
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE );
	glCullFace( GL_BACK );
	glMatrixMode( GL_MODELVIEW );
	glutMainLoop( );

	return 0;	
}