c实现 图像dither算法_【图像】抖动算法实现真彩色图片高细节256色降级处理【旧帖,效果不好,勿用】...

这篇博客介绍了一个使用C语言实现的图像抖动算法,用于将真彩色图片降级处理为256色,同时保持较高的细节。通过VB界面展示了算法的工作流程,并提供了调色板生成、图像处理等功能。
摘要由CSDN通过智能技术生成

[Visual Basic] 纯文本查看 复制代码VERSION 5.00

Begin VB.Form frmMain

Caption = "取得调色板"

ClientHeight = 6465

ClientLeft = 120

ClientTop = 450

ClientWidth = 16440

LinkTopic = "frmMain"

OLEDropMode = 1 'Manual

ScaleHeight = 431

ScaleMode = 3 'Pixel

ScaleWidth = 1096

StartUpPosition = 3 '窗口缺省

Begin VB.PictureBox picDither

Align = 3 'Align Left

BorderStyle = 0 'None

Height = 6465

Left = 0

ScaleHeight = 431

ScaleMode = 3 'Pixel

ScaleWidth = 457

TabIndex = 6

Top = 0

Visible = 0 'False

Width = 6855

Begin VB.HScrollBar HSDither

Height = 255

Left = 1440

Max = 0

TabIndex = 12

TabStop = 0 'False

Top = 3000

Width = 2415

End

Begin VB.PictureBox picColor4

AutoRedraw = -1 'True

BackColor = &H00000000&

BorderStyle = 0 'None

Height = 495

Left = 1800

ScaleHeight = 33

ScaleMode = 3 'Pixel

ScaleWidth = 33

TabIndex = 11

Top = 0

Visible = 0 'False

Width = 495

End

Begin VB.PictureBox picColor3

AutoRedraw = -1 'True

BackColor = &H00000000&

BorderStyle = 0 'None

Height = 495

Left = 1200

ScaleHeight = 33

ScaleMode = 3 'Pixel

ScaleWidth = 33

TabIndex = 10

Top = 0

Visible = 0 'False

Width = 495

End

Begin VB.PictureBox picColor2

AutoRedraw = -1 'True

BackColor = &H00000000&

BorderStyle = 0 'None

Height = 495

Left = 600

ScaleHeight = 33

ScaleMode = 3 'Pixel

ScaleWidth = 33

TabIndex = 9

Top = 0

Visible = 0 'False

Width = 495

End

Begin VB.PictureBox picColor1

AutoRedraw = -1 'True

BackColor = &H00000000&

BorderStyle = 0 'None

Height = 495

Left = 0

ScaleHeight = 33

ScaleMode = 3 'Pixel

ScaleWidth = 33

TabIndex = 8

Top = 0

Visible = 0 'False

Width = 495

End

Begin VB.PictureBox picResult

AutoRedraw = -1 'True

BackColor = &H00000000&

BorderStyle = 0 'None

Height = 495

Left = 2400

ScaleHeight = 33

ScaleMode = 3 'Pixel

ScaleWidth = 33

TabIndex = 7

Top = 0

Visible = 0 'False

Width = 495

End

End

Begin VB.PictureBox picRightPanel

Align = 4 'Align Right

BorderStyle = 0 'None

Height = 6465

Left = 15345

ScaleHeight = 431

ScaleMode = 3 'Pixel

ScaleWidth = 73

TabIndex = 0

Top = 0

Width = 1095

Begin VB.PictureBox picProgress

BackColor = &H8000000C&

Height = 255

Left = 0

ScaleHeight = 13

ScaleMode = 3 'Pixel

ScaleWidth = 69

TabIndex = 14

Top = 4320

Width = 1095

Begin VB.CommandButton cmdProgress

Enabled = 0 'False

Height = 195

Left = 0

Style = 1 'Graphical

TabIndex = 15

Top = 0

Width = 1035

End

End

Begin VB.CheckBox ChRandomPalette

Caption = "产生随机调色板"

Height = 615

Left = 0

Style = 1 'Graphical

TabIndex = 13

Top = 3600

Width = 1095

End

Begin VB.PictureBox picPal

AutoRedraw = -1 'True

BackColor = &H00000000&

BorderStyle = 0 'None

Height = 1095

Left = 0

ScaleHeight = 73

ScaleMode = 3 'Pixel

ScaleWidth = 73

TabIndex = 5

Top = 2400

Width = 1095

End

Begin VB.OptionButton OpDitherPic

Caption = "抖动图"

Enabled = 0 'False

Height = 495

Left = 0

Style = 1 'Graphical

TabIndex = 4

Top = 1920

Value = -1 'True

Width = 1095

End

Begin VB.OptionButton OpSrcPic

Caption = "原图"

Enabled = 0 'False

Height = 495

Left = 0

Style = 1 'Graphical

TabIndex = 3

Top = 1440

Width = 1095

End

Begin VB.CommandButton cmdDither

Caption = "抖动"

Enabled = 0 'False

Height = 615

Left = 0

TabIndex = 1

Top = 0

Width = 1095

End

End

Begin VB.PictureBox picSrcPic

AutoRedraw = -1 'True

AutoSize = -1 'True

BorderStyle = 0 'None

Height = 255

Left = 0

ScaleHeight = 255

ScaleWidth = 135

TabIndex = 2

Top = 0

Visible = 0 'False

Width = 135

End

End

Attribute VB_Name = "frmMain"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

'==============================================================================

'作者:0xAA55

'论坛:http://www.0xaa55.com/

'版权所有 (C) 2013-2014 技术宅的结界

'请保留原作者信息,否则视为侵权。

'------------------------------------------------------------------------------

Option Explicit

Private Const COLORS_MAX As Long = 256

Private Const COLORS_BITS As Long = 8

Private Const DIST_MAX As Long = 200000

Private Type RGBQUAD

B As Byte

G As Byte

R As Byte

X As Byte

End Typ

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用Verilog实现Jarvis dither和误差扩散的代码: ```verilog module jarvis_dither_error_diffusion( input [7:0] pixel_in, output [7:0] pixel_out, input clk, input rst ); reg signed [8:0] quant_error; reg signed [8:0] dither_noise; reg signed [8:0] dithered_pixel; reg signed [8:0] err1, err2, err3, err4, err5, err6, err7, err8; assign pixel_out = dithered_pixel; always @(posedge clk) begin if (rst) begin quant_error <= 0; dither_noise <= 0; dithered_pixel <= 0; err1 <= 0; err2 <= 0; err3 <= 0; err4 <= 0; err5 <= 0; err6 <= 0; err7 <= 0; err8 <= 0; end else begin quant_error <= pixel_in - dithered_pixel; dither_noise <= (quant_error >> 5) + (quant_error >> 6) + (quant_error >> 7) + (quant_error >> 8); dithered_pixel <= pixel_in + dither_noise + err1; err1 <= quant_error + ((dither_noise * 7) >> 4); err2 <= ((dither_noise * 5) >> 4) + err3; err3 <= ((dither_noise * 3) >> 4) + err4; err4 <= (dither_noise >> 4) + err5; err5 <= (dither_noise >> 5) + err6; err6 <= (dither_noise >> 6) + err7; err7 <= (dither_noise >> 7) + err8; err8 <= dither_noise >> 8; end end endmodule ``` 这个模块接受一个8位像素值作为输入,并使用Jarvis dither和误差扩散算法添加噪声。在每个时钟上升沿,它计算当前采样的量化误差,并加上一个由该误差的一个分数位和五分之一、六分之一、七分之一和八分之一位组成的噪声成分,以产生一个输出像素值。此外,它还将误差扩散到相邻的像素,以帮助减少量化误差产生的噪声。这种方法可以用于改善图像质量,特别是在低比特深度的情况下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值