【问题标题】:How to get and display the levels on color or bw bitmap image如何获取和显示彩色或黑白位图图像的级别
【发布时间】:2011-04-26 03:06:10
【问题描述】:

在 Photoshop 中有一个工具可以让您调整图像的层次。我希望能够做同样的事情。我在网上看到了显示级别的示例,但它们适用于每个单独的颜色通道(红色、绿色、蓝色或 alpha 或 CMYK),而不是像 Photoshop 输入级别中的组合视图(见下文)。

另外,作为奖励,有没有办法找到最佳的阴影和高光输入级别设置,基本上是自动级别按钮确定的设置?

更新:

我想我离得更近了,但我不确定。这是我拼凑的方法。第一张图片是我的结果,第二张是分析 Google 徽标的 Photoshop 结果:

更新 2:

好的,我想我明白了。代码如下。它大部分时间都在工作,大部分时间。

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

我的结果:

Photoshops 结果:

等级法:

        /**
         * 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);



【问题讨论】:

  • 也许组合级别是指亮度(转换为黑白后的像素值),如0.299 * R + 0.587 * G + 0.114 * B
  • 我不知道该怎么做。图形不是我的强项。
  • 对于图像的每个像素,使用公式获取亮度值,然后增加相应的计数器(256之一)。您将在这 256 个计数器中获得级别分布。将这些值绘制为线条,您将获得如上图所示的级别图片。
  • 我想我明白了。我会发回我找到的。
  • 我想我越来越近了,但级别不匹配。我已经用更新更新了原始帖子。

标签: flash actionscript-3 flex4


【解决方案1】:

对于图像的每个像素,使用公式获取亮度值,然后增加相应的计数器(256 之一)。您将在这 256 个计数器中获得级别分布。将这些值绘制为线条,您将获得如上图所示的级别图片。
(从 cmets 复制以做出正确答案)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多