What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Turning a Dataset into a Color Library


phospholipid

Member
Messages
9
Likes
3
We have a project where the final media will have a color palette limited to 454 colors. We have a conversion from the media's color selection to RGB. So, from an XML file I created a CSV file, meaning I have both if necessary, of 454 colors with a name and their RGB values.


I need to create a color library so that I can put an image in photoshop and then change it to indexed color so that it ONLY uses these 454 colors.


Is there a way to convert or compile my csv/xml file to a photoshop ACT file? I feel like there must be. I do *not* want to enter 454 colors by hand.


Thanks so much for any advice. Attached is a screenshot for reference.

Screen Shot 2014-12-11 at 11.37.57 AM.png


JH
 

phospholipid

Member
Messages
9
Likes
3
Hey, all. I'm sorry to bump this query. I am, of course, wondering if there are any thoughts out there? Or if not perhaps somebody might have suggestions on a different forums I might post this question to.

I appreciate all consideration. Cheers!
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
I'll try to get back to u later today, but I see problems if u r trying to get this to work in PS because I think its indexed color mode maxes out at 256 colors, just like GIFs. U may have to switch over to a program like Matlab, and write some code.

Also, if this has anything to do with your name / biochemistry, check out NIH's ImageJ software. A huge number of specialized modules have been written for it, and it has a fairly active user's community.
 
Last edited:

phospholipid

Member
Messages
9
Likes
3
You know, if it would make it easier, we could probably go through the color selections of 454 and narrow it down to 256 colors. I'm sure that wouldn't be too tough. Even so, automating the process from data would be far easier than entering it by hand. I appreciate the ideas. It's been a while since I wrote code, but I bet I could pull it off.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
So, if you want to do a bit of programming, one possibility is that you do your initial work in AI instead of PS because of several advantages that Illustrator offers in this area. For example, here is some relatively simple Illustrator Javascript code to rename swatches:

https://forums.adobe.com/thread/1278580?tstart=0

You then could transfer the set over to PS.
---------------

Another possibility is to use the Adobe Swatch Exchange file format ( *.ase) and change the names in there. Again, it requires a bit of programming, but the file format is laid out here:
https://forums.adobe.com/thread/322021?tstart=0

...and a nice summary of various file formats for color swatches here:
http://www.selapa.net/swatches/colors/fileformats.php
----------------

I found some sample code for this approach, but unfortunately, I must have closed the window. If you are interested in this approach, it shouldn't be too hard to find.

Obviously, you have to decide whether you want to spend time programming, or spend time spent doing a tedious, but very straightforward typing task. Perhaps you could pay some kid to do the latter and be done with it, LOL.

HTH,

Tom M

PS - If you gave us more info about the actual end use of the process, we might be able to guide you in other directions. For example:

a) A tutorial on performing densitometric analysis of 1D gels using ImageJ
b) One of the *many* ImageJ plugins that deal with color analysis.
 

phospholipid

Member
Messages
9
Likes
3
I'm working with a textile artist who is doing a really interesting project in, of all media, cross-stitch. She is giving me images--generally .png--that she wants me to then turn into cross-stitch patterns. A cross stitch pattern *basically* looks just like an old 8-bit nintendo image. (See example.)

So, what I do is work on the image to get it to where I think it will work the best, then I put it in an indexed color space, then I reduce the image size to only a few dozen pixels--to whatever looks appropriate for the pattern to be successful.

The data file you're looking at above represents the RGB color matches (roughly) for all 454 of the colors offered by the embroidery floss company. I figure that by telling Photoshop to pull *only* from those colors when it creates the indexed image, that we will then be able to create an index for each image of exactly what threads the artist we are supporting should use in her final embroidery. Make sense?

Perhaps there is a better way to go about it. Illustrator... ?

JH

P.S. Her project is not dopey squid.

chobotnicka-rozkres.gif
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Oh, thanks for the info ,,, was I off base when I thought it might have been a scientific application. :redface: Let me think about it for a bit.

Tom
 

phospholipid

Member
Messages
9
Likes
3
I wish I could be even more specific, but we have to protect the artist's project. It's very very cool. When it's done we can share a link to the installation.

Thanks so much for your consideration.
 

thebestcpu

Guru
Messages
2,988
Likes
2,747
Hi Phospholipid
An ACT file is on 768 bytes long and all it is is a series of RGB triples in a series of 256 triples. The first triple is index 0 and the last index 255. Here is a link to Adobe file formats that contains ACT as one of many in the link: http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1055819

Personally, the approach I would take is creating a VBA program in Excel to output this binary file from the data in the spreadsheet, and then take the created file and store it in the location here all the other PS indexed files belong.

That takes a small amount of programming by you or someone that takes on that task. The difficultiy is not the program itself, yet having the programming knowledge.

Hope this gives you another direction to consider.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
@thebestcpu -

Thank you for providing another link to Adobe's official file format specification document.

Unfortunately, as you may know, some of the file formats (including some that may be of use to the OP) have not been officially released to the public, so quite a few programmers have reverse engineered these formats and posted their results for others to use.

The third link I posted in message #5 in this thread is a comprehensive summary (with clickable links) of both official AND unofficial file format specifications, as well as quite a few examples of what one would see if you opened one of these files in a hex editor. This more comprehensive document links to the Adobe document you found.

Also, your suggestion to use VBA could certainly work, but since the OP is not a programmer, I thought he might find it easier to start from actual Javascript code snippets such as I provided in my first link in message #5, above.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
phospholipid -

A suggestion, and then a question followed by a suggestion ...

#1:

If I understand you correctly, you essentially want to perform automated color identification on images of hairy, fuzzy fibers, If this is indeed the case, because of shadowing of one thread by another, there will be large differences in brightness from one pixel to the next, but the hue, and to a lesser extent, the saturation does not vary so wildly. Below, I attached the original, Hue, Saturation, and Lightness images, in that order, for an example textile pattern that I found on the web.

Put differently, as you move from one pixel to the next within an area of one type of fiber, the R, G, and B values will all go up and down by large amounts, but they will do so, more or less proportionally. Such large swings in all the numbers will make anything but the coarsest discrimination almost impossible. In contrast, if you use just the hue, or a combination of the hue and saturation as the basis on which you classify the fibers, this method will be able to make much finer, more reliable distinctions between one type of fiber and another.

So, my first, very strong recommendation is that you switch from an RGB based method to an HSB or a L*a*b representation of the images (ie, and intentionally disregard the B, L, or V component in your classification process).

---------------

#2:

Is it correct to assume that within each image, there will only be a few different types (colors) of fibers. In other words, is it safe to assume that you will never have dozens, and certainly not hundred of different types of fibers in each image?

If the above assumption is true, then your indexed color method of classification will be much more prone to misclassification errors than other methods. Specifically, the indexed color method is almost certainly going to tell you that the image contains many different variants of each of the small number of colors that actually are present. Although it will be an improvement, even if you switch over to a HSB or L*a*b classifier as suggested above, you will still run into this problem.

Here's a simple way to understand why this will occur: Suppose the only variation between fibers is hue (so that we can completely ignore saturation and brightness for the moment). The indexed color method is essentially dividing up the hue axis into hundreds of different bins, and then placing each pixel in each bin (which represents a different indexed color). Since, I presume, there are only a few different types of fibers in each image, if you constructed a histogram of this, you would only see a small number of distinct peaks, each of which is almost guaranteed to be many bins in width. So, it may be obvious to you that there are only, say, three different types (colors) of fiber in that image, but the indexed color method will likely say that there are dozens of types. I don't think you want this.

A much less error prone classification procedure would be to first calculate the center of each of these peaks (in the hue histogram mentioned above). Because of the large number of pixels contributing to each of these peaks, the average hue of each peak can be calculated with vastly higher accuracy than any one measurement. Then you simply find the color in your catalog with the nearest hue.

If you are interested in this method, I can tell you how to pursue it. Most likely, it would involve very little (or no) programming on your part because color classification is an extremely common problem in many fields, and software exists that already does most, if not all of what you need. For example, take a look at this ImageJ page, and move your cursor over each of the small pix on the RHS of the page. Most of these examples from biology are doing almost exactly what you want to do. For example, many employ a technique called "k-means clustering" to find the centroid of each of the peaks in not just one dimensional histograms (eg, hue only), but in 2D histograms, as well (eg, hue and saturation, or "a" and "b" from L*a*b).

OTOH, if my initial assumption (ie, only a few different types of yarn are used in each image) is wrong, then ignore the approach that I just suggested because if dozens or hundreds of different types of yarn are in each image, my method won't offer much improvement over an indexed color method.

HTH,

Tom M
 

Attachments

  • example1-acr-ps02a_sRGB-01.jpg
    example1-acr-ps02a_sRGB-01.jpg
    118.2 KB · Views: 13
  • example1-acr-ps03b_sRGB-01-HSB_analysis-hue_rotated-01_hue.jpg
    example1-acr-ps03b_sRGB-01-HSB_analysis-hue_rotated-01_hue.jpg
    154.3 KB · Views: 13
  • example1-acr-ps03a_sRGB-01-HSB_analysis-02_saturation.jpg
    example1-acr-ps03a_sRGB-01-HSB_analysis-02_saturation.jpg
    250.9 KB · Views: 13
  • example1-acr-ps03a_sRGB-01-HSB_analysis-03_lightness.jpg
    example1-acr-ps03a_sRGB-01-HSB_analysis-03_lightness.jpg
    212.7 KB · Views: 13

Tom Mann

Guru
Messages
7,223
Likes
4,343
1. To make my explanation of the number and widths of the peaks more clear, here is the hue histogram for the example image that I posted. Note: there are two major colors present in this area, so that there are two, nicely separate peaks in the hue histogram, but because of inevitable noise and other problems, each peak is not an infinitely narrow spike, but has substantial width. If you tried to assign each of the hues to a fiber color, the process would probably tell you that there were 50 to 100 different types of fiber used in this small patch of material.

hue_histogram-rotated_so_it_isnt_centered_around_zero.jpg


2. To illustrate that it's better to classify on the basis of hue (and maybe saturation) rather than on the basis of R, G, or B, I've also attached their histograms. Note that there are no distinct peaks whatsoever in these histograms, so classification in this color space would be much more prone to error.

R_G_and_B_histograms.jpg


3. And, finally, for completeness, here are the histograms for the same image in L*a*b coordinates. Once again, it's easy to see the tremendous superiority of either HSL or Lab over RGB for such classification tasks.

histograms_for_L_a_and_b.jpg


Tom M

PS - BTW, in case you are wondering why an image with a large red area doesn't have a peak on either side of zero degrees, I rotated the hue scale to move the red peak up, so it didn't straddle zero.
 

phospholipid

Member
Messages
9
Likes
3
Hey, Tom.

Actually, our workflow is in the *other* direction. Here's what we are doing:

1) The artist receives an image of something unusual. For our example, I'll say she gets a photograph of open heart surgery.
2) I take that image and do some erasing and highlighting so we get an image that will make a good pattern. Then I do some contrast correction. We do very little here except shape it.
3) Then we turn that image into a cross-stitch pattern, print it, give it to the artist, and she stitches it out. The end result will be a fiber image that is recognizable as open heart surgery, but in a media you would never expect to see that.

The question is about #3. When we turn the image into a cross-stitch pattern, we essentially follow the rules for making an image a Nintendo image: indexed color and then decrease the image size. What we want to do is tell photoshop, "Hey, when you make this pictures an indexed color image, make sure to ONLY select colors from these 454 colors." Those 454 colors will correspond to the color definitions of the floss company. Thus, if we do that, then we can tell the artist, "Hey, for this picture you will need threads A, B, C, D, etc... "

Is that a better description?

JH
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
I must not understand your workflow.

For example, when you say, "...Hey, when you make this pictures an indexed color image, make sure to ONLY select colors from these 454 colors.", in fact, I am offering a way to improve this selection process. Specifically, the method I outlined will reduce the number of colors of colors needed by the artist to the minimum necessary to get good quality, and makes the selection of each of these much more accurate.

My method doesn't care if the starting image for the classification is a picture of colored threads (like I showed), or a picture of heart surgery, it will do a good job on each. In fact, I would think it would be a huge benefit to the cross-stitch person if they knew that they could get a very acceptable result with say, only a dozen different, accurately selected types of thread, instead of having to worry that they might be told to use a couple of hundred different types, but all but the first dozen hardly make any difference in the final product.

Thoughts,

Tom
 
Last edited:

thebestcpu

Guru
Messages
2,988
Likes
2,747
Hi phospholipid

Another non Photoshop option to consider that converts images to cross stitch patterns already including floss colors for DCM or Anchor is Cstitch at http://cstitch.sourceforge.net/

This may or may not be the direction you want to take yet thought it was worth considering. Check out the various pages such as the home page and documentation page. Lots of capabilities.

John Wheeler
 

Paul MR

The Script Master
Messages
382
Likes
206
I don't know if you still wish to create an ACT file from a CSV file, if you do it is possible. The easiest way it to use Bridge to create the file.
I have put together an example csv file, instuctions and the javaScript for Bridge in the zip file, hope it might be of use?
 

Attachments

  • JPG from CSV.zip
    1.4 KB · Views: 7

dv8_fx

Retired Administrator
Messages
13,761
Likes
4,789
I don't know if you still wish to create an ACT file from a CSV file, if you do it is possible. The easiest way it to use Bridge to create the file.
I have put together an example csv file, instuctions and the javaScript for Bridge in the zip file, hope it might be of use?

PAUL MR TO THE RESCUE AGAIN!!!!!!! :yourock:

You're like a Santa all year round.... sneaks in suddenly, drops a present and quietly disappears ........ til next time when needed.

Thanks from of all of us at PSG for your much appreciated help and your groooooovy scripts.......
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Really nice find, John! I had no idea such a program exists. It may answer all his needs with almost no work required.

Thanks!

Tom
 

phospholipid

Member
Messages
9
Likes
3
Hey there, Tom. My apologies. I didn't read your previous posts carefully at all. Doh! That's what happens when you read and post on the run.

Your solutions made total sense. However, it is entirely likely that she'll be using dozens and dozens of colors of floss that are very close together. Do you think it will still be an effective solution?
 

Top