Skip to main content

XYB Jpeg 이미지

· By springkim · 2 min read

Google에서 개발한 jpegli는 jpg이미지를 mozjpeg보다 더 작게 압축할 수 있다.

예시 명령어는 cjpegli original.jpg output.jpg --chroma_subsampling=420 -q 90으로 9.5MB의 이미지가 3.7MB로 줄어든다.

-rw------a  1 spring           9.5M Feb  4 02:03 original.jpg
-rw------a  1 spring           3.7M Feb 13 07:00 output.jpg

여기서 cjpegli original.jpg output.jpg --chroma_subsampling=420 -q 90 --xyb로 색공간을 XYB로 주면 크기는 1.2MB로 더 작아진다.

-rw------a  1 spring           9.5M Feb  4 02:03 original.jpg
-rw------a  1 spring           1.2M Feb 13 07:02 output.jpg

다만 XYB색공간을 지원하는 이미지 뷰어는 아직까진 반디뷰, 꿀뷰밖에 없다.

opencv로 XYB색상을 BGR로 바꾸려면 아래 코드를 사용한다.\

cv::Mat jpegli_xyb_to_bgr(const cv::Mat &xyb_img) {
    static const cv::Matx33f XYB_TO_BGR_MATRIX(
        1.78f, 0.98f, -0.45f,
        0.07f, 0.98f, -0.47f,
        0.11f, 1.00f, 0.87f
    );

    static const cv::Scalar XYB_TO_BGR_OFFSET(-148.5f, 34.8f, -91.1f);

    cv::Mat bgr_float;
    xyb_img.convertTo(bgr_float, CV_32FC3);
    cv::transform(bgr_float, bgr_float, XYB_TO_BGR_MATRIX);
    cv::add(bgr_float, XYB_TO_BGR_OFFSET, bgr_float);

    cv::Mat bgr;
    bgr_float.convertTo(bgr, CV_8UC3);

    return bgr;
}
Usage: cjpegli INPUT OUTPUT [OPTIONS...]
 INPUT
    the input can be JXL, PPM, PNM, PFM, PAM, PGX, PNG, APNG, JPEG
 OUTPUT
    the compressed JPEG output file
 --disable_output
    No output file will be written (for benchmarking)
 -x key=value, --dec-hints=key=value
    color_space indicates the ColorEncoding, see Description();
    icc_pathname refers to a binary file containing an ICC profile.
 -d maxError, --distance=maxError
    Max. butteraugli distance, lower = higher quality.
    1.0 = visually lossless (default).
    Recommended range: 0.5 .. 3.0. Allowed range: 0.0 ... 25.0.
    Mutually exclusive with --quality and --target_size.
 -q QUALITY, --quality=QUALITY
    Quality setting (is remapped to --distance).    Default is quality 90.
    Quality values roughly match libjpeg quality.
    Recommended range: 68 .. 96. Allowed range: 1 .. 100.
    Mutually exclusive with --distance and --target_size.
 --chroma_subsampling=444|440|422|420
    Chroma subsampling setting.
 -p N, --progressive_level=N
    Progressive level setting. Range: 0 .. 2.
    Default: 2. Higher number is more scans, 0 means sequential.
 --xyb
    Convert to XYB colorspace
 --std_quant
    Use quantization tables based on Annex K of the JPEG standard.
 --noadaptive_quantization
    Disable adaptive quantization.
 --fixed_code
    Disable Huffman code optimization. Must be used together with -p 0.
 --num_reps=N
    How many times to compress. (For benchmarking).
 --quiet
    Suppress informative output
 -v, --verbose
    Verbose output; can be repeated, also applies to help (!).

 -h, --help
    Prints this help message. Add -v (up to a total of 2 times) to see more options.
Updated on Feb 13, 2026