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

Check Median Value of Active Layer

New Here ,
Jul 05, 2018 Jul 05, 2018

Hi Community,

Is it possible to check median values of the current active Layer image via Photoshop scripting ?

I am planning to write a script to check if the current layer's median value is greater than median >= 250.

Similar to this one - How do you get Histogram Mean Value?  But instead of Mean I would like to get median values.

Please help me in this ?

Thanks

TOPICS
Actions and scripting
861
Translate
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 ,
Jul 05, 2018 Jul 05, 2018

I think this might work to give you the median value. It basically get the image's pixel dimension, then cuts that in half, as the median is the middle value. The it just goes through the histogram and adds up the values in each value (how many pixels have a value of 0 etc). When it reaches the middle point of pixels, it stops and shows the array number of the histogram that contains that value.

#target photoshop

var doc = activeDocument;

var dimTotal = parseInt(doc.width*doc.height);

var dimHalf = dimTotal/2

var histo = doc.histogram

var runningCount = 0

for(var i=0;i<histo.length;i++){

    runningCount +=histo;  

    if(runningCount>=dimHalf){

        alert('i= '+ i)

        break;

        }

    }

Translate
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 ,
Jul 05, 2018 Jul 05, 2018
LATEST

I can’t write scripts so I am not sure if this will help or not… I pulled this from another script, but it appears to work correctly simply swapping mean to median…though I am not sure about the activeLayer vs. activeDocument:

var mean =  meanHist(activeDocument.histogram).toFixed(0);

var median =  medianHist(activeDocument.histogram).toFixed(0);

Re: sort bright photos from dark photos in bridge?

Translate
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