Colorsampler's CMYK values different from Info panel

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

kpt

Colorsampler's CMYK values different from Info panel

Post by kpt »

I don't understand why I get different results from the below color sampler script compared to when I use Photoshop's color sampler tool and look at the Info palette:



I have converted the image to the ColorMatch RGB profile and my CMYK working space is SWOP.

Code: Select allvar colorSampler = function(i) {  // code found on this forum
  var doc = app.activeDocument;
  var cs = doc.colorSamplers;
  if (cs.length == 0)
    return undefined;
  var cp = cs[0];
  var A = 5;         /* 5x5 kernel */
  var r = (A-1)/2;
  var x = Math.round(cp.position[0]-r);
  var y = Math.round(cp.position[1]-r);
  doc.selection.select([[x,y], [x+A,y], [x+A,y+A], [x,y+A]], SelectionType.REPLACE, 0, false);
  doc.activeLayer.applyAverage();
  var sc = new SolidColor();
  sc = cp.color;
  executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );
  doc.selection.deselect();
  return sc;
};

main = function() {
  var sc = colorSampler(0);
  if (!sc)
    return alert("No color sampler!");
  alert(Math.round(sc.cmyk.cyan) + "," + Math.round(sc.cmyk.magenta) + "," + Math.round(sc.cmyk.yellow));
};

main();

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Colorsampler's CMYK values different from Info panel

Post by Mike Hale »

I would say check two things.

1. Make sure you are looking in the right spot. The RGB values at the top are different than the RGB values from the colorSampler so that is my guess why the values don't match. The top is showing values from another place in the doc. Change the display color for the sampler to CMYK and see if you get a closer match.

2. Make sure the size in the options bar match the size in the script, 5x5.

BTW if I use the RGB values from the colorsampler in the colorPicker the CMYK values are very close.
kpt

Colorsampler's CMYK values different from Info panel

Post by kpt »

Ah, I had to fake the screen dump, actually merging two screen dumps - that's why the numbers are different

But changing the color sampler readout to CMYK suddenly got everything working! I'll investigate further, but thanks for pointing that out!
kpt

Colorsampler's CMYK values different from Info panel

Post by kpt »

Mike, any idea why the script produces different output when the readout for the color sampler is changed from RGB to CMYK?
Mike Hale

Colorsampler's CMYK values different from Info panel

Post by Mike Hale »

I tried it on several image and the alert numbers match the CMYK sampler numbers in the info panel. Even out of gamut colors.
kpt

Colorsampler's CMYK values different from Info panel

Post by kpt »

Even when the readout is set to RGB?

Mike Hale

Colorsampler's CMYK values different from Info panel

Post by Mike Hale »

Yes, the only time the values were not very close was when I forgot to set the Sample Size in the options bar. It was set to 11x11 and because the script is sampling a 5x5 area the numbers were off.