在Photoshop中有一個工具,可讓您調整圖像的水平。我希望能夠做同樣的事情。我在網上看到了一些示例,它們顯示了各個顏色通道(紅色,綠色,藍色或alpha或CMYK),但不是像Photoshop輸入級別(參見下文)中的組合視圖。如何獲取並顯示顏色或bw位圖圖像的水平
此外,還有一種方法可以找到最佳陰影並突出顯示輸入級別設置,基本上是自動級別按鈕確定的設置?
更新:
我覺得我更接近,但我不知道。這是我拼湊在一起的方法。第一個形象是我的結果,第二個是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);
< S:BitmapImage的ID = 「selectedPicture」 WIDTH = 「100%」 高度= 「100%」 的scaleMode = 「信箱」/>
< MX:UIComponent ID = 「sprite1」/>
<小號:BitmapImage id =「thresholdGraph」width =「100%」height =「45」/>
也許組合水平是指亮度(轉換爲黑白後的像素值),如「0.299 * R + 0.587 * G + 0.114 * B」。 – alxx 2011-04-26 06:38:10
我不知道該做什麼。圖形不是我的強項。 – 2011-04-26 08:06:20
對於圖像的每個像素,使用公式獲取亮度值,然後增加相應的計數器(256之一)。你將在這256個計數器中獲得等級分佈。將這些值繪製爲線條,然後像上面那樣得到關卡圖像。 – alxx 2011-04-26 08:44:27