Database design to store image color pattern in MySQL for searching Image by color

前端 未结 3 849
时光说笑
时光说笑 2021-01-18 19:58

I am building a image galley using PHP and MySQL where I want to implement Image search by it\'s color. By following Imagick::getImageHistogram i got the mo

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 20:16

    How about you first times all the red values by the number of times they appeared and then add those values together to get the overall red value. Then divide by the total number of times appeared. Do the same for Green and Blue.

    For example:

    total red = ((252*125)+(194*126)+(109*11440)+(2*12761)+(255*40769)) 
                / (125 + 126 + 11440 + 12761 + 40769)
              = 180
    

    Then just store them in the database like

                 id         red      green       blue     image_path
    Image 1      1          225      134         4        /dir/
    Image 2      2          143      0           145      /dir/
    Image 3      3          239      200         111      /dir/
    

    If you were searching for Red images you could do something like:

    SELECT id, image_path WHERE red > 200 AND blue < 100 AND green < 100
    

    Im not sure of the specifics, but you could mess around with the values.

提交回复
热议问题