วิธีที่จะแปลงเป็น gray8_view_t ต้องเป็น rgb8_view_t โดยการใช้เพิ่ม::จิลและสร้าง rgb8_image_t วัตถุจากมัน?

0

คำถาม

ตั้งแต่เพิ่ม::จิลยังไม่รองรับ gray8_view_t เขียนสำหรับ BMPNAME รูปแบบ,ผมต้องการจะแปลง gray8_view_t จะ rgb8_view_t. นี่คือสิ่งที่ฉันพยายามดังนั้นถึงตอนนี้

auto rgb_view = boost::gil::planar_rgb_view(width, height, pixels, pixels, pixels, width);

หน่วยเป็นพิกเซลมีดิบ(หน่วยเป็นพิกเซล)จาก gray8_view_t วัตถุดังนั้นฉันยอมให้สเปนเซอร์รี้ดครับ r=g=บี=โดยมีหน่วยเป็นพิกเซล แต่ boost::gil::write_view(ofstream, rgb_view, boost::gil::bmp_tag()) ให้ผมว่าคงภาพได้ที่นี่ รู้บ้างมั้ย?

ปรับปรุง: โดยการใช้ sehe เป็นตัวอย่างเช่นรหัส http://coliru.stacked-crooked.com/a/daa0735f774b727fฉันสามารถเอาสีทสนทนาต้อง compile กับ color_converted_view<gil::rgb8_view_t>. แต่มันไม่ compile ตอนที่ฉันใช้ boost::gil::write_view ต้องสร้างแฟ้มภาพจากกลับค่า color_converted_view<gil::rgb8_view_t>. ฉันเดาว่าฉันจะต้องสร้างจริงๆ rgb8_image_t วัตถุจากคืนค่า. ยังไงฉันสามารถแปลงเป็นที่กลับค่า color_converted_view<gil::rgb8_view_t> ต้องการจริงๆ rgb8_image_t วัตถุ? ขอบคุณ!

#include <boost/gil.hpp>
#include <fstream>
namespace gil = boost::gil;

int main()
{
        std::ifstream in("gray8_image_t_sample.jpg", std::ios::binary);
        gil::gray8_image_t img;
        gil::read_image(in, img, gil::jpeg_tag());
        gil::gray8_view_t gv = gil::view(img);
        std::ofstream ofs1("test_image.png", std::ios::out | std::ios_base::binary);
        gil::write_view(ofs1, gv, gil::png_tag()); // This works

        auto rgbv = gil::color_converted_view<gil::rgb8_view_t>(gv);
        std::ofstream ofs2("test_image.bmp", std::ios::out | std::ios_base::binary);
        gil::write_view(ofs2, rgbv, gil::bmp_tag()); // this does not compile
} 

หนึ่งในข้อความผิดพลาดฉันกำลังจะ

\boost\gil\color_base_algorithm.hpp(170,76): error G1A4676F8: no member named 'layout_t' in 'boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mp11::mp_list<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mp11::mp_list<std::integral_constant<int, 0>, std::integral_constant<int, 1>, std::integral_constant<int, 2>>>>, false, std::allocator<unsigned char>>' [clang-diagnostic-error]

นี่คือ gray8_image_t ฉันกำลังใช้แฟ้ม

boost boost-gil c++
2021-11-19 23:46:27
1

คำตอบที่ดีที่สุด

1

โอเคที่เหลือปัญหาก็เป็นแค่เป็น misspecified ต้นแบร์กิวเมนต์ color_converted_view คาดหวังให้เป็นปลายทางพิกเซลประเภท:

#include <boost/gil.hpp>
#include <boost/gil/extension/io/bmp.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <boost/gil/extension/io/png.hpp>
#include <fstream>
namespace gil = boost::gil;

int main()
{
    std::ifstream in("gray8_image_t_sample.jpg", std::ios::binary);
    gil::gray8_image_t img;
    gil::read_image(in, img, gil::jpeg_tag());
    gil::gray8_view_t gv = gil::view(img);
    gil::write_view("input.png", gv, gil::png_tag());

    auto rgbv = gil::color_converted_view<gil::rgb8_pixel_t>(gv);
    gil::write_view("output.png", rgbv, gil::png_tag());
    gil::write_view("output.bmp", rgbv, gil::bmp_tag());
}

กับ resuling แฟ้ม:

2021-11-22 17:00:37

ขอบคุณมากครับ!
BunRieuCua

เชียร์ส ยินดีต้อนรับสู่ stackoverflow. อย่าลืมไปเลือกตั้งและยอมรับ(meta.stackexchange.com/questions/5234/...)
sehe

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่