Message Boards Message Boards

0
|
5819 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Sorting cat breeds by color

Posted 8 years ago

Hello, I've just started out programming with Wolfram and have decided to try and sort all of the cats under the 'cat breeds photos' database by their fur color. I've already found their fur color by using

DominantColors[ImageCrop[i, {50, 50}] , 1]}

This works for every single cat, but my issue is that I can find no way to sort them by color. They all come out as RGB values of color but I'm looking for either some way to establish either the R, G, or B as a variable by which I can measure and sort the cats, or honestly by any other measure which makes sense. I thought about hexadecimal but it seems very inconvenient to work with in Wolfram. If anybody could give me some guidance I would greatly appreciate it.enter image description here

POSTED BY: Nathan Urban
4 Replies
Posted 8 years ago

@Bianca: Thanks for the suggestion, I never came across that functions so perhaps I'll try to rebuild my function using this to play around with it a little bit, it sounds interesting.

@Sam: No real reason, I just wanted a way to browse the cats and figured fur color would be a sufficient way of doing this, it has no real application but there was a small programming event over the span of a weekend where you're meant to build something and after deciding to give wolfram a shot I chose to make this. I've actually finished the project so sorry about that but I will remember to post code in the future.

My finished project

CatSort=Partition[Column[{#, DominantColors[ImageCrop[#, {38,38}] ,1]},Alignment->Center]&/@(Take[,71]), 71];
Flatten[DominantColors[ImageCrop[#, {38,38}],1]&/@(Take[,71])]
Sort[CatSort]

Final= Flatten[Reverse@SortBy[GatherBy[CatSort[[1]],#[[1,2]]&],#[[1,1,2]]&] ]

Essentially because all cat pictures in the database are centered on the cat, I take the middle 38 pixels(This was the sweetspot I found where all cat colors were identified correctly, not too small of a window to get one fur hair of a different color, and small enough that the background color did not interfere for the smaller cats. I only took one DominantColor per cat as to keep things simple.)

I had the most trouble with nestling, the numerical RGB colors were what I was going to sort by(The R value specifically), and so there were two people there who showed me how to find the specific nestle the RGB was stored in, and how to both keep the colors and cats together while sorting only by color (This was tricky, I found a roundabout way on accident to gather the colors separately from the cats and sort those, but they showed me how to do this while keeping the cats+colors still paired.

This is probably really messy code but I'm just glad I found a way to make it work, I'll probably revisit it because there's a lot more I could learn about how data is stored in Wolfram.

Attachments:
POSTED BY: Nathan Urban

That's true, Sam, but if Nathan's original idea works well, it could be used to identify potential breeds of a cat "in the wild" and he could test if it's better or worse than ImageIdentify... That said, I have no idea how closely coat color really correlates to breed. Anyway, the built-in information about coat colors would be great to check the results of the image-based solution.

I had the same initial response to the background color problem, but looking at the examples in the original post, it seems to work. He's using DominantColors, which is notably not an averaged color, so as long as the image is cropped in such a way that the cat occupies the largest area (and/or the central area, whatever the function is using), Nathan's approach should work.

POSTED BY: Bianca Eifert

You should post your code as copy-paste and / or attach Mathematica notebook. That's a common curtesy to help people to help you.

BTW, why color? Isn't there a lot of color in the background, which got nothing to do with cats? Why not by some of their physical properties:

EntityProperties["CatBreed"]

enter image description here

POSTED BY: Sam Carrettie

Yay, cats! You might be looking for the ColorDistance function. It can compare colors, lists of colors, or entire images.

POSTED BY: Bianca Eifert
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract