最近我遇到了一些很奇怪的问题,请看下面的代码片段
<canvas id="cancan" width="320", height="480">One color image</canvas>
<script type="text/javascript">
function imageLoaded(ev) {
element = document.getElementById("cancan");
c = element.getContext("2d");
im = ev.target; // the image, assumed to be 200x200
// read the width and height of the canvas
width = element.width;
height = element.height;
// stamp the image on the left of the canvas:
c.drawImage(im, 0, 0);
// get all canvas pixel data
imageData = c.getImageData(0, 0, width, height);
console.log(imageData.data[0] + " " + imageData.data[1] + " " + imageData.data[2]);
// output is "243 52 47"
// matlab and c# output is: "237 36 27"
}
im = new Image();
im.onload = imageLoaded;
im.src = "imgtest1.jpg"; // image is 320x480
</script>本例中使用的imgtest1.jpg是常量-每个像素都是(237,36,27)。getImageData()返回的像素颜色有所不同--它比matlab返回的颜色更亮--比如matlab--你知道原因是什么吗?
发布于 2013-02-28 19:58:52
亮度或亮度或强度可以计算为(R+G+B)/3 (参见HSI颜色代码)。在您的示例代码结果之后,很明显您的输出图像比原始图像要亮一点,因为您的R-G-B值比原始图像(来自Matlab或C++)要高。
问题一定是“为什么你的代码要计算更高的值?”我不知道,但您可以重新缩放这些值,以获得相同的亮度。
https://stackoverflow.com/questions/14588408
复制相似问题