使用boost :: gil编写jpeg文件>> [

问题描述 投票:0回答:1
我正在尝试读取jpeg文件,进行一些简单的转换,然后使用boost :: gil库将其写出。现在,即使读取文件,提取非白色点(它仅包含红色和白色点)并将它们写入另一个文件中,也让我感到非常困惑。我希望图片相同,但是会发生这种情况:

这是输入图片。Original Picture

这是输出图片:enter image description here

这是我读取非白色坐标的方式:

vector<Point2D> points; //load points from file rgb8_image_t img; jpeg_read_image(in_file_path, img ); assert( 2 == img._view.num_dimensions ); const auto dimensions = img._view.dimensions(); assert( 2 == dimensions.num_dimensions ); row_width = dimensions.x; col_height = dimensions.y; size_t white_cnt = 0; size_t non_white_cnt = 0; for ( uint32_t x = 0; x < dimensions.x; ++x ){ for ( uint32_t y = 0; y < dimensions.y; ++y ){ const rgb8_pixel_t& pix = const_view(img)( rgb8_image_t::point_t(x,y) ); if ( !is_white(pix) ){ points.push_back( Point2D {x,y} ); } } }

这就是指出相同之处的方法

rgb8_image_t img(row_width,col_heigth); rgb8_pixel_t white(255,255,255); rgb8_pixel_t red(255,0,0); rgb8_pixel_t blue(0,0,255); fill_pixels( view(img), white ); cout << "printing " << points.size() << "points" << std::endl; for ( Point2D p : points ){ const auto x = p[0]; const auto y = p[1]; cout << x <<"," << y << endl; view(img)( rgb8_image_t::point_t( x,y ) ) = red; } jpeg_write_view( out_file_path, const_view(img));

为了完整性,这是is_white检查:

bool is_white( const boost::gil::rgb8_pixel_t& pix ){ const auto r = boost::gil::at_c<0>(pix); const auto g = boost::gil::at_c<1>(pix); const auto b = boost::gil::at_c<2>(pix); constexpr auto MAX_VAL = std::numeric_limits<decltype(r)>::max(); return ( MAX_VAL == r ) && ( MAX_VAL == g ) && ( MAX_VAL == b ); }

知道我在做什么错吗?

谢谢

我正在尝试读取jpeg文件,进行一些简单的转换,然后使用boost :: gil库将其写出。现在,我陷入了困境,甚至无法读取文件,提取非白点(它仅包含...

c++ boost jpeg libjpeg boost-gil
1个回答
0
投票
由于源数据中的JPEG伪像,您有许多实际上不是红色的非白色像素:
© www.soinside.com 2019 - 2024. All rights reserved.