Dithering-视觉的奇特现象

 最早对听说Dithering这个词还是看到clayman大神推荐的dx9 pipeline图,当时也没深究,今天在openGPU上有大牛对此问题给出来答案, 当时也没看懂,回来看了下wiki上关于dithering的介绍,瞬间明白了。再次借wiki的图做个小白普及吧~~(不算侵权吧。。)

这就是一个很直接的dithering的例子,图中实际只用了红蓝两种颜色,但是随着像素的变小,图片逐渐呈现出紫色。
  看到这边大家应该对dither这个操作有了个理解,它就是用少量的颜色来表现更广泛的颜色的。这么做的原因,有很多方面的用途,譬如在某一些使用lcd屏幕的嵌入式设备上能显示的色域很比较小的,在这样的设备上显示图片,如果单纯的将超过色域的颜色四舍五入的话,就会产生很明显的颜色带。(如下图)这样就需要利用dithering操作来进行修正。

原图                                       未经过dithering                           经过dithering后,颜色过渡自然很多

  具体的算法wiki上大概的介绍,有兴趣的同学可以看看:http://en.wikipedia.org/wiki/Dither
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CT image compression (a) Implement the simplified DCT compression process above for n = 2, 4, and 8 and apply it to the attached image. Show the reconstructed images for these three different cases. [3 images] Compute the PSNR values of the three reconstructed images and discuss what the PSNR value means here. (b) Use the same process in (a) with image transformed to YIQ color model and show the reconstructed image in RGB space. [3 images] Compute the PSNR values of the three reconstructed images and discuss what the PSNR value means here. Dithering 2. Dithering (30%) Convert the image cat2_gray.png to binary (black and white) image with different methods of dithering, show the results, and make some comparison with the results. (a) Apply noise (random) dithering on the provided image and show the result. [1 image] (b) Apply average dithering on the provided image and show the result. [1 image] (c) Apply error diffusion dithering (Floyd-Steinberg algorithm) on the provided image and show the result. [1 image] Image Interpolation Implement the image interpolation function to upsample an image to four times the original width and height. Implement the following two different interpolation methods and show the 4× upsampled images. (a) Apply nearest-neighbor interpolation on the low resolution image, cat3_LR.png, and compute the PSNR with the original high resolution image, cat3_HR.png. [1 image] (b) Apply bilinear interpolation on the low resolution image and compute the PSNR with the high resolution image. [1 image] (c) Apply bicubic interpolation on the low resolution image and compute the PSNR with the high resolution image. [1 image]
以下是Somogyi Stucki抖动算法的MATLAB代码: ``` function output_img = dither_somogyi_stucki(input_img) % Somogyi Stucki dithering algorithm % input_img: grayscale input image (double, range 0-1) % output_img: dithered image (binary) % Define the dithering matrix dither_mat = [0 0 0 8 4; 2 4 8 4 2; 1 2 4 2 1]/42; % Define the dimensions of the input image [height, width] = size(input_img); % Initialize the output image output_img = zeros(height, width); % Iterate over each pixel for y = 1:height for x = 1:width % Calculate the current pixel's value old_pixel = input_img(y,x); % Calculate the new pixel's value new_pixel = old_pixel + dither_mat(mod(y-1,3)+1,mod(x-1,5)+1); % Threshold the new pixel's value if new_pixel >= 0.5 output_img(y,x) = 1; else output_img(y,x) = 0; end % Calculate the quantization error quant_error = old_pixel - output_img(y,x); % Distribute the quantization error to neighboring pixels if x < width input_img(y,x+1) = input_img(y,x+1) + quant_error * 8/42; end if x < width-1 input_img(y,x+2) = input_img(y,x+2) + quant_error * 4/42; end if x > 1 && y < height input_img(y+1,x-1) = input_img(y+1,x-1) + quant_error * 2/42; end if y < height input_img(y+1,x) = input_img(y+1,x) + quant_error * 4/42; end if y < height-1 input_img(y+2,x) = input_img(y+2,x) + quant_error * 2/42; end if x < width && y < height input_img(y+1,x+1) = input_img(y+1,x+1) + quant_error * 8/42; end if x < width && y < height-1 input_img(y+2,x+1) = input_img(y+2,x+1) + quant_error * 4/42; end if x < width-1 && y < height-1 input_img(y+2,x+2) = input_img(y+2,x+2) + quant_error * 2/42; end end end % Convert the output image to binary output_img = logical(output_img); end ``` 请注意,该代码假定输入图像是灰度图像,并且其值范围为0到1。如果你的输入图像不是灰度图像或其值范围不是0到1,你需要先进行适当的处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值