-2
我正在尋找一種類似於這裏的算法http://www.cssdrive.com/imagepalette/index.php「Complete Color Pallete」,它可以查找給定照片的顏色調色板。像PHP中的pixelate照片一樣的顏色古怪
我正在尋找一種類似於這裏的算法http://www.cssdrive.com/imagepalette/index.php「Complete Color Pallete」,它可以查找給定照片的顏色調色板。像PHP中的pixelate照片一樣的顏色古怪
您可以使用imagecolorat和一些循環讀取每個像素顏色值並計算每種顏色的頻率。您可能還想將這些步驟的顏色湊到一起,這樣就不會有平坦的直方圖。一旦你獲得了每種顏色的直方圖,並找到n個最高點,這些就是你應該使用的n種顏色。祝你好運。
function findPallete($filename, $palletesize) {
$im = imagecreatefromjpeg($filename);
$dimensions = getimagesize($filename);
$frequencies = array();
for($x=0;$x<$dimensions[0];$x++)
for($y=0;$y<$dimensions[1];$y++)
$frequencies[imagecolorat($im,$x,$y)]++;
array_multisort($frequencies,SORT_DESC);
return array_keys(array_slice($frequencies,0,$palletesize));
}