Color depth change

http://en.nicoptere.net/?p=8

 

Tags: actionscriptactionscript 3BitmapDataCGAcolor depthcolorsEGAHAM,processVGA

cover
a script to change the color depth of a bitmapData.

A couple of months ago, I tried to make a color reduction script. It was based on a series of BitmapData copyChannel / paletteMaps but it caused a lot of artefacts for the script couldn’t manage very low nor very high colors.
So I took it from the start, I tried to replace the paletteMap with thresholds which appear to be much faster. Yet it wasn’t satisfying ; it kept creating temporary bitmaps and batch processing them was still notoriously killling the performances. For instance if I wanted to reduce the color depth by 2 the script would perform (4 * 127) thresholds(one per channel) + the copy operations, which is veeeery bad. 
the good thing with this method was when you wanted to decrease significantly the color depth, it could run pretty well. with 20 or 24 thresholds in all, the speed was convincing.
But I started manipulating the pixels themselves. no more channel splitting which really did good. 
First I tried with the ByteArray and my conclusion is that it is much much slower than a get/setPixel on a locked BitmapData. and it was indeed a bad surprise…

So I resigned myself to use the good old getPixel, perform a mathematic operation and then setPixel. And it works pretty well, of course the processing time is higher than big threshold reductions but it’s constant(for a given amount of pixels) and more accurate.

see for yourslef:


I didn’t count the colors and I am not clever enough to create a real professionnal, accurate script that would handle color profiles plus I don’t really care in fact, I’m only interested in the graphical output.
so from from left to right and top-down:

  • the original BitmapData that is used to perform the tests
  • ReduceColors.toCGA( original ) : 8 colors (few! Ican still count to 8 ^^)
  • ReduceColors.toEGA( original ) : +/- 64 colors (there are dark shades too)
  • ReduceColors.toVGA( original ) : +/- 256 colors
  • ReduceColors.toHAM( original ) : +/- 4096 colors
  • ReduceColors.toSVGA( original ) : +/- 65536 colors

The class itself is quite idiot-proof, you can choose one of the presets above and use them as follow:

ReduceColors.toCGA( original:BitmapData, grayscale:Boolean, alpha:Boolean )

where original is the original BitmapData, grayscale is a Boolean value to get a grayscaleoutput(wow!) and alpha another boolean that specifies wether the thresholding should be applied to the alpha channel or not. Both are set to false by default.
For the wildests amongst you, you can directly call:

ReduceColors.reduceColors( original:BitmapData, number:int, grayscale:Boolean, alpha:Boolean )

where the additional parameter number represents the number of steps that will be created to replace the original 255. During the process, colors will be snapped to the closest value they can find in the lookup table. And That’s the very thing I ‘m not proud of, to keep both black and white, I forced them in the array by making each step equal to (255/number+2).
This +2, is all but healthy and, even though it works as such, I’m sure that it could be done in a much more elegant way. 
finally here’s a demo of a couple of settings to show you how to use the reduceColors() method:



and its little source file: reduceColors

I guess that was it,
enjoy :)

Tags: actionscriptactionscript 3BitmapDataCGAcolor depthcolorsEGAHAM,processVGA


<?xml version="1.0"?> <launch> <!-- Basic camera parameters --> <arg name="camera_name" default="camera"/> <!-- open device delay time 100m--> <arg name="connection_delay" default="100"/> <arg name="log_level" default="none"/> <arg name="publish_tf" default="true"/> <arg name="tf_publish_rate" default="10.0"/> <arg name="enable_frame_sync" default="true"/> <arg name="time_domain" default="system"/><!-- "device", "global", "system" --> <arg name="uvc_backend" default="libuvc"/><!-- "libuvc" or "v4l2" --> <!-- The default value of device_preset is `Default`. Only the G330 series is supported. For more information, refer to --> <!-- https://www.orbbec.com/docs/g330-use-depth-presets/ --> <arg name="device_preset" default="Default"/> <arg name="diagnostics_frequency" default="1.0"/> <arg name="sync_mode" default="Free Run"/> <arg name="enable_hardware_d2d" default="true"/> <!-- Color camera parameters --> <arg name="color_width" default="1280"/> <arg name="color_height" default="720"/> <arg name="color_fps" default="15"/> <arg name="enable_color" default="true"/> <arg name="color_format" default="ANY"/> <!-- color rotation degree : 0, 90, 180, 270 --> <arg name="color_rotation" default="0"/> <arg name="enable_color_auto_exposure" default="true"/> <!-- -1 means not set, other value bigger than 0, the value is the exposure time in ms--> <arg name="color_exposure" default="-1"/> <!-- Depth camera parameters --> <arg name="depth_width" default="640"/> <arg name="depth_height" default="576"/> <arg name="depth_fps" default="15"/> <arg name="enable_depth" default="true"/> <arg name="depth_format" default="ANY"/> <arg name="depth_registration" default="true"/> <!-- depth rotation degree : 0, 90, 180, 270 --> <arg name="depth_rotation" default="0"/> <!-- IR camera parameters --> <arg name="ir_width" default="640"/> <arg name="ir_height" default="576"/> <arg name="ir_fps" default="15"/> <arg name="enable_ir" default="true"/> <arg name="ir_format" default="ANY"/> <!-- Common IR camera parameters --> <arg name="enable_ir_auto_exposure" default="true"/> <!-- Depth/IR/Left IR/Right IR exposure is same --> <!-- -1 means not set, other value bigger than 0, the value is the exposure time in us--> <arg name="ir_exposure" default="-1"/> <arg name="enable_ir_long_exposure" default="false"/> <!-- Point cloud parameters --> <arg name="enable_point_cloud" default="true"/> <arg name="enable_colored_point_cloud" default="false"/> <arg name="ordered_pc" default="false"/> <!-- Gemini 335/335L only support SW align mode, Please DO NOT change it --> <arg name="align_mode" default="SW"/> <!-- filter switch --> <arg name="enable_threshold_filter" default="false"/> <arg name="threshold_filter_max" default="-1"/> <arg name="threshold_filter_min" default="-1"/> <!-- IMU parameters --> <arg name="enable_sync_output_accel_gyro" default="true"/> <arg name="enable_accel" default="true"/> <arg name="accel_rate" default="200hz"/> <arg name="accel_range" default="4g"/> <arg name="enable_gyro" default="true"/> <arg name="gyro_rate" default="200hz"/> <arg name="gyro_range" default="1000dps"/> <arg name="liner_accel_cov" default="0.01"/> <!-- Misc parameters --> <arg name="usb_port" default=""/> <arg name="serial_number" default=""/> <arg name="device_num" default="1"/> <arg name="retry_on_usb3_detection_failure" default="false"/> <arg name="enable_d2c_viewer" default="false"/> <arg name="laser_energy_level" default="-1"/> <arg name="enable_ldp" default="true"/> <arg name="enable_heartbeat" default="false"/> <arg name="enable_hardware_reset" default="false"/>深度和图像对齐打开了吗
08-02
内容概要:本文提出了一种基于融合鱼鹰算法和柯西变异的改进麻雀优化算法(OCSSA),用于优化变分模态分解(VMD)的参数,进而结合卷积神经网络(CNN)与双向长短期记忆网络(BiLSTM)构建OCSSA-VMD-CNN-BILSTM模型,实现对轴承故障的高【轴承故障诊断】基于融合鱼鹰和柯西变异的麻雀优化算法OCSSA-VMD-CNN-BILSTM轴承诊断研究【西储大学数据】(Matlab代码实现)精度诊断。研究采用西储大学公开的轴承故障数据集进行实验验证,通过优化VMD的模态数和惩罚因子,有效提升了信号分解的准确性与稳定性,随后利用CNN提取故障特征,BiLSTM捕捉时间序列的深层依赖关系,最终实现故障类型的智能识别。该方法在提升故障诊断精度与鲁棒性方面表现出优越性能。; 适合人群:具备一定信号处理、机器学习基础,从事机械故障诊断、智能运维、工业大数据分析等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①解决传统VMD参数依赖人工经验选取的问题,实现参数自适应优化;②提升复杂工况下滚动轴承早期故障的识别准确率;③为智能制造与预测性维护提供可靠的技术支持。; 阅读建议:建议读者结合Matlab代码实现过程,深入理解OCSSA优化机制、VMD信号分解流程以及CNN-BiLSTM网络架构的设计逻辑,重点关注参数优化与故障分类的联动关系,并可通过更换数据集进一步验证模型泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值