A Cyberpunk Style Image Maker
Version 1.0.1 (2.76 KB) by
Chun
Converts an image to a Cyberpunk style image, but only work well for some particular styles of images
function imgOut = cyberpunkify(inputData, varargin)
% cyberpunkify_v2: Converts an image to a Cyberpunk style.
% 将图像转换为赛博朋克风格。
%
% This version combines the core color grading logic from the first version
% with the improved digital effects of the v2.0 framework.
% 该版本结合了第一版的核心调色逻辑与v2.0框架下的数字效果改进。
%
% USAGE:
% imshow(cyberpunkify('city.jpg'));
% imgOut = cyberpunkify(imageData, 'glow_strength', 40);
% 1. Input Parser / 参数解析
p = inputParser;
addRequired(p, 'inputData');
addParameter(p, 'brightness', -0.2, @isnumeric);
addParameter(p, 'contrast', 0.3, @isnumeric);
addParameter(p, 'highlight_threshold', 0.7, @isnumeric);
addParameter(p, 'glow_strength', 30, @isnumeric);
addParameter(p, 'aberration_strength', 3, @isnumeric);
addParameter(p, 'scan_line_opacity', 0.1, @isnumeric);
addParameter(p, 'vignette_strength', 0.6, @isnumeric);
parse(p, inputData, varargin{:});
params = p.Results;
% 2. Load Image & Initialization / 读取图像与初始化
if ischar(params.inputData) || isstring(params.inputData)
img_orig = imread(params.inputData);
else if isnumeric(params.inputData) && ndims(params.inputData) == 3
img_orig = params.inputData;
else, error('Invalid input. Must be a file path or an RGB image matrix.');
end
end
img_orig = im2double(img_orig);
[h, w, ~] = size(img_orig);
fprintf('Cyberpunkify v2.0 Initialized with v1.0 color grading.\n');
% --- 第一层:建立基础暗调 (Day to Night) ---
fprintf('第一层:模拟夜景,构建蓝/紫暗调...\n');
base_img = imadjust(img_orig, ...
[0; 1], ...
[0 + params.contrast/2; 1 - params.contrast/2], ...
1 + params.brightness);
base_img(:,:,1) = base_img(:,:,1) * 0.85; % 减少红色
base_img(:,:,2) = base_img(:,:,2) * 0.9; % 减少绿色
base_img = min(max(base_img, 0), 1);
% --- 第二层:提取并染色高光 (Neon Lights) ---
fprintf('第二层:点亮霓虹,渲染洋红/青色高光...\n');
gray_img = rgb2gray(img_orig);
highlight_mask = gray_img >= params.highlight_threshold;
% 向量化生成颜色渐变图
magenta = [1, 0, 0.8];
cyan = [0, 0.8, 1];
ratio_vec = linspace(0, 1, w);
magenta_3d = reshape(magenta, 1, 1, 3);
cyan_3d = reshape(cyan, 1, 1, 3);
color_map = (1 - ratio_vec) .* magenta_3d + ratio_vec .* cyan_3d;
neon_layer = color_map .* highlight_mask;
% --- 第三层:创造辉光氛围 (Glow/Bloom) ---
fprintf('第三层:添加辉光效果,营造氛围感...\n');
if params.glow_strength > 0
glow_layer = imgaussfilt(neon_layer, params.glow_strength);
else
glow_layer = zeros(size(neon_layer));
end
% 恢复 v1.0 的直接叠加方式
processed_img = base_img + neon_layer*1.2 + glow_layer*1.5;
processed_img = min(max(processed_img, 0), 1);
% --- 第四层:增加数字感 (Digital Feel) ---
final_img = processed_img;
% Chromatic Aberration / 色差
if params.aberration_strength > 0
fprintf('Layer 4.1: Adding chromatic aberration...\n');
s = params.aberration_strength;
R = final_img(:,:,1); G = final_img(:,:,2); B = final_img(:,:,3);
R_shifted = imtranslate(R, [s, s]); B_shifted = imtranslate(B, [-s, -s]); % 对角线偏移
R_shifted = R_shifted(1:h, 1:w); B_shifted = B_shifted(1:h, 1:w);
final_img = cat(3, R_shifted, G, B_shifted);
end
% Scan Lines / 扫描线
if params.scan_line_opacity > 0
fprintf('Layer 4.2: Adding scan lines...\n');
scan_lines = ones(h, 1) * linspace(1, 1 - params.scan_line_opacity, w);
scan_lines(1:3:end,:) = scan_lines(1:3:end,:) * 0.9;
final_img = final_img .* scan_lines;
end
% Vignette / 暗角
if params.vignette_strength > 0
fprintf('Layer 4.3: Adding vignette...\n');
[X, Y] = meshgrid(linspace(-1, 1, w), linspace(-1, 1, h));
gauss = exp(-(X.^2 + Y.^2) * params.vignette_strength);
final_img = final_img .* gauss;
end
% 7. Final Output / 最终输出
imgOut = im2uint8(min(max(final_img, 0), 1));
fprintf('Cyberpunkify v2.0 Process Complete.\n');
end
Cite As
Chun (2025). A Cyberpunk Style Image Maker (https://se.mathworks.com/matlabcentral/fileexchange/182069-a-cyberpunk-style-image-maker), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2023b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
