Colors

TalkHacking LibraryThing

Join LibraryThing to post.

Colors

1bnielsen
Edited: Jul 3, 2023, 1:45 pm

I had an idea recently of using my bunch of scanned covers for something. The basic idea is find _one_ color for each cover. That's easily done with a library / tool / whatever to scale the given cover to a 1 x 1 pixel image and take the color of that.

$ jpegtopnm morsesgreatestmysteryandotherstories.jpg | pnmscale -xsize 1 -ysize 1 | pnmtoplainpnm | tail -1

97 95 98

so that cover is 97/255 red, 95/255 green and 98/255 blue.

The next step is to find some way of grouping colors into names, since I want to find say all red covers without having to program what I mean by "red". Someone already did that because you can specify Tomato as the color of something in HTML. Here's a table of that lot of named colors:

https://wiki.librarything.com/index.php/User:Bnielsen/ColorNames

So for the color "97 95 98" I just send my program into the list of color names and find the nearest named color (by treating them as simple 3D points). This gives the color Gray::DimGray.

Next step is to do this for all my covers and add it as a column in the database / spreadsheet I transform the export file into.

Voila:
$ cat /tmp/lt.rdb | perl /tmp/row Cover_Color mat '/Salmon/' | perl /tmp/column Book_Id | perl /tmp/headchg --delete | xargs | sed -e 's/ /+OR+/g'

21361692+OR+21871303+OR+22707271+OR+22781456+OR+23615280+OR+25555324+OR+25626893+OR+28418715+OR+56928422+OR+59231135+OR+62859155+OR+110481501+OR+117187077+OR+122442925+OR+124077730+OR+155929360+OR+221086518+OR+233893877+OR+235122961

allowing me to construct a search for all Salmon coloured covers in my library. (BTW it would be nice if the search input field would allow for searching more than the current 12 book ids. But at least we can construct an url to the same effect.)

https://www.librarything.com/catalog/bnielsen?&collection=-1&deepsearch=...

There are 143 named colors in the list, but currently my covers only use 76 of them. Here's a count of the various colors:

49 Blue::CadetBlue
3 Blue::CornflowerBlue
1 Blue::LightBlue
14 Blue::LightSteelBlue
32 Blue::MidnightBlue
1 Blue::RoyalBlue
3 Blue::SkyBlue
48 Blue::SteelBlue
2 Brown::Bisque
129 Brown::Brown
22 Brown::BurlyWood
31 Brown::Chocolate
8 Brown::DarkGoldenrod
9 Brown::Goldenrod
111 Brown::Maroon
198 Brown::Peru
586 Brown::RosyBrown
203 Brown::SaddleBrown
24 Brown::SandyBrown
448 Brown::Sienna
178 Brown::Tan
21 Brown::Wheat
319 Gray::Black
440 Gray::DarkGray
1213 Gray::DarkSlateGray
1592 Gray::DimGray
89 Gray::Gainsboro
1078 Gray::Gray
108 Gray::LightGray
135 Gray::LightSlateGray
211 Gray::Silver
114 Gray::SlateGray
2 Green::DarkCyan
2 Green::DarkGreen
842 Green::DarkOliveGreen
50 Green::DarkSeaGreen
5 Green::ForestGreen
1 Green::LightSeaGreen
2 Green::MediumAquamarine
4 Green::MediumSeaGreen
2 Green::Olive
31 Green::OliveDrab
32 Green::SeaGreen
10 Green::Teal
4 Green::YellowGreen
8 Orange::Coral
1 Orange::OrangeRed
1 Orange::Tomato
7 Pink::LightPink
1 Pink::MediumVioletRed
8 Pink::PaleVioletRed
48 Purple::DarkSlateBlue
21 Purple::Lavender
4 Purple::Purple
1 Purple::RebeccaPurple
3 Purple::Thistle
18 Red::Crimson
14 Red::DarkRed
17 Red::DarkSalmon
92 Red::FireBrick
168 Red::IndianRed
5 Red::LightCoral
2 Red::Salmon
8 White::AntiqueWhite
2 White::Beige
2 White::FloralWhite
3 White::GhostWhite
31 White::Linen
2 White::MistyRose
3 White::OldLace
5 White::SeaShell
6 White::Snow
42 White::WhiteSmoke
93 Yellow::DarkKhaki
1 Yellow::Moccasin
1 Yellow::PeachPuff

2Keeline
Jul 3, 2023, 2:03 pm

Going from RGB values to color names is a topic that more than a few programmers have attempted. Other than "pure" spot colors, you are unlikely to get something that is going to match an ideal HTML color name that might be out there. So you have to find out what range of values or colors that is closest.

Here are a couple pages that talk about this depending on what languages you care to use. Most of the time you need to only have access to the language to use a tool written in it (like Python). Values can be passed to the program and the result used for other purposes.

How to assign a name to a color (2022)
https://blogs.sas.com/content/iml/2022/01/12/closest-color-name.html

RGB to Color Names in Python — The Robust Way (2021)
https://medium.com/codex/rgb-to-color-names-in-python-the-robust-way-ec4a9d97a01...

ImageMagick is a suite of image manipulation tools for the command line that is available for the major desktop operating systems There are several tools available and these are just some of the pages that refer to them and color space in general.

https://magickstudio.imagemagick.org/Color.html
https://imagemagick.org/script/color.php
https://imagemagick.org/Usage/color_basics/

Usually you will want some limited palette to work from and find the colors that are closest to that. Although other colors can be distinguished and even named, it may be counterproductive to do this. Many people grew up with a traditional box of 64 Crayola crayons. I think the selection and names of colors have changed over time.

But when someone says "I remember a book. It was red." These fine-grained differences don't matter so much. Perhaps an 8- 16- or 64-color box of Crayola crayons might be enough.

James

3bnielsen
Jul 3, 2023, 3:46 pm

>2 Keeline: Thanks. Good discussion and useful links. I found out that my list of 141 names contained 143 lines :-)
LightSalmon was listed as both "Red LightSalmon" and "Orange LightSalmon", and MediumSlateBlue as "Blue MediumSlateBlue" and "Purple MediumSlateBlue".
Comparing with the table provided with SAS gave some HoneyDew versus Honeydew differences and a single color where the difference was real :
RebeccaPurple 102-051-153 versus DarkSlateGrey 047-079-079.

But yes, I don't want thousands of names, but it seems 141 colors suffice :-)

It was quite fun coding this and the result is slightly better than what I expected. I.e. the 19 salmon covers actually have a salmon-like color, when I look at them.

4Keeline
Jul 3, 2023, 9:51 pm

There are 216 so-called web-safe colors. But how much this corresponds with book colors (jacket or cover depending on what you have uploaded) is hard to say. Having a list that is 25% smaller is probably a help.

Here is another script that implements a "nearest color" algorithm. It seems like it might have some interesting possibilities. There may be other scripts on the site that can be used with it.

http://www.fmwconcepts.com/imagemagick/nearestcolor/index.php

James

5bnielsen
Jul 4, 2023, 5:26 am

>4 Keeline: yes, I considered the 216 web-safe colors too, but some of them aren't named. And the list from imagemagick has grey0 grey1 grey2 ... grey 255 :-) almost. which are too many to be useful.

Now the next fun question is what the 141-73 colors that doesn't match a cover look like :-) Maybe no one likes a cover that's PukeGreen?

6TimSharrock
Jul 4, 2023, 1:25 pm

the XKCD colour survey may be relevant - I certainly enjoyed reading about it: https://blog.xkcd.com/2010/05/03/color-survey-results/

7bnielsen
Edited: Jul 5, 2023, 11:22 am

>6 TimSharrock: Thanks. I'll consider adding sickly yellow and baby shit brown to my list :-)

ETA:
The 65 colors that don't match any of my covers are:

AliceBlue, Aqua, Aquamarine, Azure, BlanchedAlmond, Blue, BlueViolet, Chartreuse, Cornsilk, Cyan, DarkBlue, DarkMagenta, DarkOrange, DarkOrchid, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DodgerBlue, Fuchsia, Gold, Green, GreenYellow, HoneyDew, HotPink, Indigo, Ivory, Khaki, LavenderBlush, LawnGreen, LemonChiffon, LightCyan, LightGoldenrodYellow, LightGreen, LightSalmon, LightSkyBlue, LightYellow, Lime, LimeGreen, Magenta, MediumBlue, MediumOrchid, MediumPurple, MediumSlateBlue, MediumSpringGreen, MediumTurquoise, MintCream, NavajoWhite, Navy, Orange, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PapayaWhip, Pink, Plum, PowderBlue, Red, SlateBlue, SpringGreen, Turquoise, Violet, White, Yellow

My guess is that most covers are a bit off compared to a pure color. I.e. A completely red cover will have author and title added in another color, so the average color of the cover will not be red, but some slightly darker red. Maybe I should look for "the most common color" rather than "the average color". Or maybe it won't matter.

8bnielsen
Jul 5, 2023, 4:35 pm

>7 bnielsen: I coded "the most common color" just for fun, but that turned out not to be what I wanted. I.e. a picture with mostly red colors and a smallish white sign would get "white" as most common color, since all the reds were slightly different reds :-)

9brightcopy
Aug 21, 2023, 5:33 pm

I dabbled in this a bit while working on a VR reconstruction of a private library. Definitely a Hard Problem to actually solve past the 80% mark. We can only hope that AI will eventually provide the solution.

10bnielsen
Aug 22, 2023, 6:07 am

>10 bnielsen: It's also a fuzzy problem. I.e. https://en.wikipedia.org/wiki/The_dress
So maybe we can only find a solution when we define the problem :-)

Also from >3 bnielsen:
LightSalmon was listed as both "Red LightSalmon" and "Orange LightSalmon", and MediumSlateBlue as "Blue MediumSlateBlue" and "Purple MediumSlateBlue".

11conceptDawg
Aug 23, 2023, 4:04 pm

I'm checking in to make sure you know of the recent "Color" additions to the LT catalog columns. Basically, we've computed the base colors and some included colors for every cover in your catalog. I know that it might not be exactly what you want, but wanted to make sure you knew about it.

12bnielsen
Aug 24, 2023, 5:05 am

Nice. But it seems to be on only a few of my covers. I.e. this search show 18 books, but no cover color information. (I've added the column to style C.)

https://www.librarything.com/catalog/bnielsen?&deepsearch=else%20fischer

13lorax
Aug 24, 2023, 5:31 pm

Yeah, it's there sometimes, but when it is it seems to be wrong about 10-20% of the time (due to the cover that Syndetics chooses for an ISBN being different from the one I have for the same ISBN). And I'd expect that it's there less frequently for non-English titles. If I had the time I'd be doing something like bnielsen too, because the only thing worse than no data is unfixable bad data. (I've shared in the past that six of the seven colors Syndetics/LT thinks are "purple" in my library are not, and that most of the covers I'd think are "purple" are not considered purple by the tags.

https://www.librarything.com/catalog.php?view=lorax&colorterm=184

vs

https://www.librarything.com/catalog/lorax?tag=purple%20cover

(tagged by the highly scientific method of using Cover View and squinting at it to say "that one looks mostly purple to me"). I wouldn't expect an exact match, but that's pretty lousy. If you use a style with Cover Colors included you can see that most of my purple ones don't have purple chosen as the main color.

14conceptDawg
Aug 26, 2023, 9:34 am

Yep. It's not perfect but it's what we have for now. It's not my project so I can't speak to it but I'm sure you'll see improvements over time. And, as always, any feedback is noted and appreciated.

15knerd.knitter
Aug 28, 2023, 12:29 pm

>12 bnielsen: At the moment, the only covers being used are those that come from Syndetics, not any member uploaded or anything like that. That's why the cover is being displayed in that column so you know to what the colors are referring. See here for more information on the feature: https://www.librarything.com/topic/351506

16bnielsen
Aug 28, 2023, 4:11 pm

>15 knerd.knitter: My point is just that I have so few covers with this information as to make the feature useless for me at the moment. I don't claim that it is useless for others :-)