簡體   English   中英

如何在 PHP 或 Python 中將灰度圖像還原/轉換為 RGB 圖像

[英]How to revert / convert grayscale image to RGB image in PHP or Python

我已成功將圖像轉換為灰度,我想將灰度圖像恢復為 RGB 圖像。 請幫忙。 提前致謝。 這是我將圖像轉換為灰度的代碼


$gdlogo = imagecreatetruecolor($width_logo, $heigth_logo);
for((int) $start_x=0;$start_x<$width_logo;$start_x++){
    for((int) $start_y=0;$start_y<$heigth_logo;$start_y++){      
        $color_index = imagecolorat($imglogo, $start_x, $start_y);
        $color_tran = imagecolorsforindex($imglogo, $color_index);
        $red = $color_tran["red"];
        $green = $color_tran["green"];
        $blue = $color_tran["blue"];
        $image_get[$start_x][$start_y] =$red.$green.$blue;
        $colors= (0.299*$red) + (0.587*$green) + (0.114*$blue);
        $color = imagecolorallocate($gdlogo,$colors[0],$colors[1],$colors[2]); 
        imagesetpixel($gdlogo,$start_x,$start_y, $color);
    }
}

在那里我看到了一種通過乘以顏色索引來改變灰度圖像的方法:(0.299 * $ red) + (0.587 * $ green) + (0.114 * $ blue); 所以它變成灰色我認為如果顏色指數除以 (0.299 / $ red) + (0.587 / $ green) + (0.114 / $ blue); 它將返回RGB,但不起作用

顏色應該在除數之前。

所以與其:

($ red/0.299)+($ green/0.587)+($ blue/0.114)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM