2011-04-26 142 views
1

在Photoshop中有一个工具,可让您调整图像的水平。我希望能够做同样的事情。我在网上看到了一些示例,它们显示了各个颜色通道(红色,绿色,蓝色或alpha或CMYK),但不是像Photoshop输入级别(参见下文)中的组合视图。如何获取并显示颜色或bw位图图像的水平

此外,还有一种方法可以找到最佳阴影并突出显示输入级别设置,基本上是自动级别按钮确定的设置? Photoshop Adjustment Levels Dialog

更新:

我觉得我更接近,但我不知道。这是我拼凑在一起的方法。第一个形象是我的结果,第二个是Photoshop的结果既分析谷歌标志:

更新2:

好吧,我想我得到了它。代码如下。它大多数时间都在工作。

附加学分: https://pixelero.wordpress.com/2008/06/19/flash-10-bitmapdatahistogram/#comment-448

我的结果:
My results

Photoshops结果:
Photoshop Results

水平的方法:

 /** 
     * Get a histogram of the grayscale levels 
     * */ 

     private function drawGrayscaleHistogram(bitmapImage:BitmapImage, sprite:Sprite):BitmapData { 
      var grayScale:Array = [0.3086, 0.3086, 0.3086, 0, 0, 0.3086, 0.3086, 0.3086, 0, 0, 0.3086, 0.3086, 0.3086, 0, 0, 0, 0, 0, 1, 0]; 
      var color:Array = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; 
      var filter:ColorMatrixFilter = new ColorMatrixFilter(grayScale); 
      var histogram:Vector.<Vector.<Number>>; 
      var graphWidth:int = sprite.width; 
      var graphHeight:int = sprite.height; 
      var g:Graphics = sprite.graphics; 
      var vector:Vector.<Number>; 
      var bitmapData:BitmapData; 
      var maxValue:int; 
      var value:int; 
      var i:int; 

      // clone the bitmap 
      bitmapData = bitmapImage.bitmapData.clone(); 

      // convert it to gray scale 
      bitmapData.applyFilter(bitmapImage.bitmapData, bitmapImage.bitmapData.rect, new Point(), filter); 

      // get histogram 
      histogram = bitmapData.histogram(); 

      // since it's grayscale the red green and blue are all the same 
      vector = histogram[0]; 

      // get the max value for drawing the graph 
      for (var s:* in vector) { 
       if (vector[s]>maxValue) { 
        maxValue = vector[s]; 
       } 
      } 

      //trace(maxValue); 
      //maxValue = 300; 

      // create white background 
      g.clear(); 
      g.beginFill(0xFFFFFF, 1.0); 
      g.drawRect(0, 0, graphWidth, graphHeight); 

      // draw each line 
      for each (value in vector) { 
       g.lineStyle(1, 0); 
       g.moveTo(i, graphHeight); 
       g.lineTo(i++, Math.max(0.0, graphHeight-value * graphHeight/maxValue)); 
      } 

      // assign it to bitmap data 
      // so we can resize easily if we want 
      bitmapData = new BitmapData(graphWidth, graphHeight, true, 0x00000000); 
      bitmapData.draw(sprite); 

      return bitmapData; 
     } 

用法:

levelsBitmapImage.source = drawGrayscaleHistogram(selectedPicture,sprite1);

< S:BitmapImage的ID = “selectedPicture” WIDTH = “100%” 高度= “100%” 的scaleMode = “信箱”/>
< MX:UIComponent ID = “sprite1”/>
<小号:BitmapImage id =“thresholdGraph”width =“100%”height =“45”/>

+1

也许组合水平是指亮度(转换为黑白后的像素值),如“0.299 * R + 0.587 * G + 0.114 * B”。 – alxx 2011-04-26 06:38:10

+0

我不知道该做什么。图形不是我的强项。 – 2011-04-26 08:06:20

+1

对于图像的每个像素,使用公式获取亮度值,然后增加相应的计数器(256之一)。你将在这256个计数器中获得等级分布。将这些值绘制为线条,然后像上面那样得到关卡图像。 – alxx 2011-04-26 08:44:27

回答

1

对于图像的每个像素,使用公式获得亮度值,然后增加相应的计数器(256之一)。你将在这256个计数器中获得等级分布。将这些值绘制为线条,然后像上面那样得到关卡图像。