• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

how to retrieve pixel value of channel mask

Participant ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

hi all,
can we retrieve the pixel value of channel mask using script.

i want retrieve the pixel value of each channel mask in the channels panel and store that details in json file.
thank you

TOPICS
Actions and scripting

Views

425

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

What do you mean by »pixel value of channel mask«? 

• What pixel value? 

• A Channel or a Layer Mask? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

for example pixel value of color or image.
so channel mask or layer mask is a pixel image. so i need to get the pixel value of that channel mask

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

• What value/s? »pixel value of color or image« seems like a meaningless string of words to me. 

• Which exact Channel/s in an image do you need to evaluate? 

Please provide meaningful screenshots including all pertinent Panels to clarify. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

Individual Channels (if those are what you are referring to) have no color, as they are in themselves grayscale. 

 

Collecting the values of all pixels in an image will most probably necessitate utilizing RAW-images because iterating the Color Picker Tool across an image is too slow, both @Paul Riggott and @jazz-y have posted code that employs this technique, if I remember correctly. 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/reading-hex-codes-on-each-layer-of-a-...

 

But I wonder if the Histogram might suffice instead … what are you actually trying to do, how and to what end are you going to process the information you want to retrieve, …?  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

Screenshot 2023-08-10 at 9.49.02 AM.png

in the above fig. i have selected the channel. so what we are seeing in the page that i need to retrieve the pixel data of that channel mask.. so that i can store that details in json.  after that we have one tool in that we need to display the channel mask exactly how it looks in the photoshop. so if i get the code to retrieve the pixel data of channel mask image, so that i can display the channel mask in our tool for every channel mask

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

This description seems about meaningful but I don’t understand what this is about really

quote

that we have one tool in that we need to display the channel mask exactly how it looks in the photoshop.

Why employ another tool and not visualize the result in Photoshop itself? 

Can that tool not simply process image data like tif, png, …? 

In what exact form do you need the pixel data (not »pixel value« as you originally said)? Please post a sample. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

in that we also have channel panel in that we need display channel mask.. so when we load the channel mask , we retrieve details of pixel data which we stored in json file and then we display the channel mask..

can you please provide retrieving pixel data of channel mask ? is there any way to get it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Maybe you should post in your native or preferred language and we’ll see if auto-translation can help; as it is I find your posts not easy to understand. 

 

What do you mean by »pixel data« exactly

In which exact form do you need it if your other application is incapable of simply processing images? 

Please provide an actual example. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

pixel data, like. channel mask and layer mask is a pixel image . so each channel mask have pixel values like
R 255 G 255 B 170 so like this. from this pixel value channel mask will be created.

Screenshot 2023-08-11 at 12.12.07 PM.png

the above  image shows pixel values.. so through the script how to get that details of each channel mask and layer mask

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

Again: 

In which exact form do you need the pixel data? 

Unless you want a document in which the numbers are arranged in a grid the images you posted seem meaningless. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

hi @c.pfaffenbichler 

Screenshot 2023-08-11 at 2.24.48 PM.png

 so in the above fig. i will selected path 1 from channels panel as u can see . so now i want to get that pixel data . 
so i need pixel data in the form like , by using that data i should plot image from that data.. please find me which form of data that i need in this scenario?

or can we pull the rgb color data of each channel mask? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

Are you asking me what you need here? 

I already asked you repeatedly, if you don’t know I am not sure how one could help you. 

 

What is the actual problem you are trying to solve with that »one tool« you referred to? 

Why employ another »tool« at all and how does Photoshop fall short for your needs? 

What is that »tool«? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

hi @c.pfaffenbichler  can we pull the rgb color data of each channel mask? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

Quite frankly this is getting close to appearing pointless to me. 

Are you unwilling or unable to provide meaningful information? 

 

I already posted a link to code @Paul Riggott had posted to get a list of Lab values from an Lab-image; one would need to adapt that for grayscale-images and create a new temporary image for each Channel but in principle it seeems possible to me. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2023 Aug 15, 2023

Copy link to clipboard

Copied

This would create a csv-file like this 

Untitled-1.jpg

from a grayscale image. 

So you could duplicate all the channels into new files and save those temporarily (and delete them afterwards) to get the text files. 

// getGrayscalePixelsValueViaRawBasedOnCodeByByPaul
// based on code by by paul riggott;
// 2023, use it at your own risk;
File.prototype.readByte = function() {
  return this.read(1).charCodeAt(0); 
};
function convertByteToSignedByte(num){
     var dec = (num | (num % 256))-128
     return dec;
};
function convertByteToLum( num){
     var dec = Math.round((num/256)*100);
     return dec;
};
function main(){
if(!documents.length) return;
if(activeDocument.mode != DocumentMode.GRAYSCALE) {
    ("Please convert this document to grayscale mode\r Then re-run this script");
    return;
    }
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
try{
var Path = activeDocument.path;
}catch(e){var Path = '~/Desktop';}
var rawFile = new File(Path +"/"+Name +".raw");
saveGrayscaleRaw(rawFile);
var csvFile = new File(Path +"/"+Name +".csv");
var len = 0;
var W = activeDocument.width.as('px');
CountW=0;
CountH=0;
rawFile.encoding = 'BINARY';
rawFile.open('r');
csvFile.open('w');
csvFile.writeln('X,Y,grayscale');
while(!rawFile.eof){
    csvFile.write(CountW+',');
    csvFile.write(CountH+',');
    csvFile.writeln(rawFile.readByte());
     len++;
     if(len % W == 0){
         CountH++;
         CountW=0;
         }else{
     CountW++;
     }
}
rawFile.close();
csvFile.close();
rawFile.remove();
}
main();
////// save raw from a grayscale image //////
function saveGrayscaleRaw (thePath) {
var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putString( stringIDToTypeID( "fileCreator" ), "8BIM" );
var idrawFormat = stringIDToTypeID( "rawFormat" );
desc4.putObject( stringIDToTypeID( "as" ), idrawFormat, desc5 );
desc4.putPath( stringIDToTypeID( "in" ), new File( thePath ) );
//desc4.putInteger( stringIDToTypeID( "documentID" ), 63 );*/
desc4.putBoolean( stringIDToTypeID( "copy" ), true );
desc4.putBoolean( stringIDToTypeID( "lowerCase" ), true );
desc4.putEnumerated( stringIDToTypeID( "saveStage" ), stringIDToTypeID( "saveStageType" ), stringIDToTypeID( "saveBegin" ) );
executeAction( stringIDToTypeID( "save" ), desc4, DialogModes.NO );
};
function saveAsRaw(file) {
    var desc1 = new ActionDescriptor();
    var desc2 = new ActionDescriptor();
    desc2.putString( charIDToTypeID('FlCr'), "8BIM" );
    desc2.putBoolean( charIDToTypeID('ChnI'), true );
    desc1.putObject( charIDToTypeID('As  '), charIDToTypeID('Rw  '), desc2 );
    desc1.putPath( charIDToTypeID('In  '), new File( file ) );
    desc1.putBoolean( charIDToTypeID('Cpy '), true );
    executeAction( charIDToTypeID('save'), desc1, DialogModes.NO );
    };

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Found @Paul Riggott ’s post about using RAW-files on Lab-images to get a list of the Lab-values. 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/easy-way-to-extract-all-pixel-lab-val...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

LATEST

Yep.
Look at the Imaging API, specifically the getLayerMask() method.

 

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines