白底换红底

局部阈值调整

边界高斯滤波

function demo

global R
global threshold
global img
global dstColor
global rect
global mask
global biasStep biasStep = 5;
dstColor = [255 0 0]; %% background color
img = imread('g.jpg'); %% load photo
R = img(:,:,1);
[mm, nn] = size(R);
rect = [1 1 nn, mm]; threshold = 200 * ones(mm, nn); %% init threshold
figure('KeyReleaseFcn',@processCMD);
mask = R < threshold; %% init mask
processImg(img, mask, rect, dstColor);
text(20, 20, sprintf('Threshold : %d', threshold(1))) function processCMD(src, evnt)
global R
global threshold
global img
global dstColor
global rect
global mask
global biasStep if strcmp(evnt.Key, 'uparrow')
threshold = changeThreshold(threshold, rect, biasStep);
mask = R < threshold;
processImg(img, mask, rect, dstColor); elseif strcmp(evnt.Key, 'downarrow')
threshold = changeThreshold(threshold, rect, - biasStep);
mask = R < threshold;
processImg(img, mask, rect, dstColor); elseif strcmp(evnt.Key, 'leftarrow')
if biasStep > 2
biasStep = biasStep - 1;
processImg(img, mask, [], dstColor);
end
elseif strcmp(evnt.Key, 'rightarrow')
biasStep = biasStep + 1;
processImg(img, mask, [], dstColor);
elseif strcmp(evnt.Key, 'space')
%% select rect
processImg(img, mask, [], dstColor);
rect = floor(getrect());
processImg(img, mask, rect, dstColor);
elseif strcmp(evnt.Key, 'g')
I = processImg(img, mask, [], dstColor);
%% gaussian filter
G = fspecial('gaussian',[5 5],2);
Ig = imfilter(I,G,'same');
eg = repmat(imdilate(edge(mask), strel('diamond', 5)), [1 1 3]);
I(eg) = Ig(eg);
imshow(I, []);
imwrite(I, 'output.jpg') else
disp('unkown command')
disp(evnt.Key) end
tmp = threshold(rect(2) : rect(2) + rect(4) - 1, rect(1) : rect(1) + rect(3) - 1);
text(20, 20, sprintf('Threshold : %f, step : %d', tmp(1), biasStep)); function newImg = processImg(img, mask, rect, dstColor)
[mm, nn, pp] = size(img);
newImg = zeros(mm, nn, pp);
for i = 1 : 3
tmp = ones(mm, nn) * dstColor(i);
tmpImg = img(:, :, i);
tmp(mask) = tmpImg(mask);
newImg(:,:,i) = tmp;
end
newImg = uint8(newImg); imshow(newImg);
if ~ isempty(rect)
rectangle('Position', rect, 'LineWidth', 2)
end function threshold = changeThreshold(threshold, rect, bias)
threshold(rect(2) : rect(2) + rect(4) - 1, rect(1) : rect(1) + rect(3) - 1) = mean(mean(threshold(rect(2) : rect(2) + rect(4) - 1, rect(1) : rect(1) + rect(3) - 1)));
threshold(rect(2) : rect(2) + rect(4) - 1, rect(1) : rect(1) + rect(3) - 1) = bias + threshold(rect(2) : rect(2) + rect(4) - 1, rect(1) : rect(1) + rect(3) - 1);

matlab白底换红底的更多相关文章

  1. Python给照片换底色(蓝底换红底)

    环境要求 Python3 numpy函数库 opencv库 安装 下载适应版本的numpy函数库,我电脑是WIN10 64位,安装的函数库是 numpy-1.13.1+mkl-cp36-cp36m-w ...

  2. 用图来教你怎样用Photoshop蓝底转换红底

      教你怎样用红底转换成蓝底.PS其实学了这个,你就可以在白底红底蓝底之间不同转变了.   第一步   第二步   第三步   第四步         最后给你们看看对比效果图

  3. 教你用OpenCV 和 Python给证件照换底色(蓝底 <->红底->白底)

    在我们的生活中常常要用到各种底色要求的证件电子照,红底.蓝底.或者白底,而假如你手上只有一种底色的证件照,你又不想再去拍又不会PS怎么办?今天教你们用OpenCV和Python给你的证件照换底色. P ...

  4. MACD:黄白线、红绿柱与0轴关系

    一.MACD的基本问题: (1)参数:统一用12,26,9 (2)MACD   位正.位不正原则 以下四种情况是黄白线.红绿柱与0轴关系的完全分类,行情出不了这四种情况, 即便黄白线在0轴单边反复缠绕 ...

  5. OpenCV实现彩色图像轮廓 换背景颜色

    转摘请注明:https://i.cnblogs.com/EditPosts.aspx?opt=1 有时候我们需要不一样颜色的证件照,下面就用OpenCV来实现证件照的蓝底.红底等换颜色: 代码如下: ...

  6. 【PS】证件照转换背景色

    证件照转换背景色 2019-07-14  12:18:49  by冲冲 1. 需求 自由切换证件照的背景颜色(白底.蓝底.红底...) 2. 步骤 ① 双击 图层锁 解锁,弹出的"新建图层0 ...

  7. Excel修改证件照图片背景色

    在实际生活中,我们常常需要把白底证件照更改为蓝底或红底.操作步骤只需4步!   工具/原料   Excel 方法/步骤     第1步:插入白底证件照 单击[插入]---[图片],选择图片保存的位置, ...

  8. vue入门基础知识点测试

    vue入门基础知识点测试 1.文本(值绑定){{var}}----控制<div></div>的值显示当前时间,且1秒更新一次.(可查阅 setinterval 函数,时间Dat ...

  9. [汇编语言]-第九章 在屏幕中间分别显示绿底红色,白底蓝色字符串"welcome to masm!"

    ;在屏幕中间分别显示绿色,绿底红色,白底蓝色字符串"welcome to masm!" assume cs:codesg,ds:datasg,ss:stacksg datasg s ...

随机推荐

  1. 【Spark Core】TaskScheduler源代码与任务提交原理浅析2

    引言 上一节<TaskScheduler源代码与任务提交原理浅析1>介绍了TaskScheduler的创建过程,在这一节中,我将承接<Stage生成和Stage源代码浅析>中的 ...

  2. ReboletricSample工程搭建

    受到  Just Say No to More End-to-End Tests 文章链接:http://googletesting.blogspot.tw/2015/04/just-say-no-t ...

  3. gridview 横向滚动 一行显示

    http://blog.csdn.net/chin3q/article/details/6559345 http://blog.csdn.net/yuzhouxiang/article/details ...

  4. 个人开发者帐号--我是如何实现在另一台mac上真机调试的

    本文转载至 : http://blog.csdn.net/chenyong05314/article/details/8689534   注:本人有一台mac电脑,之前申请开发者帐号的时候直接就是在这 ...

  5. RTSP/RTMP/HLS/HTTP流媒体播放器EasyPlayer

    EasyPlayer播放器系列项目 EasyPlayer是由EasyDarwin开源团队开发和维护的一个流媒体播放器系列项目,随着多年不断的发展和迭代,不断基于成功的实践经验,发展出包括有: Easy ...

  6. Git 忽略上传文件设置 .gitignore exclude

    1.项目根目录下创建.gitignore vi .gitignore #输入需要忽略的文件,支持正则表达式, *.o *.exe*.pyc 可以用git status来检查是否生效 未添加文件前: M ...

  7. SQL 系统表应用

    查看link server select DD.System,DD.DB,DD.previous_processing_dte, DD.processing_dte,LS.LinkServerName ...

  8. php mcrypt加密实例

    <?php //当前mcrypt支持的加密模型 $modes_list = mcrypt_list_modes(); // Array // ( // [0] => cbc // [1] ...

  9. CORS 理解(不要那么多术语)

    摘要 谈到跨域,不论前端还是后端,多少有点谈虎色变,面试中也常会问到这些问题,浏览器和服务器端到底怎么做才能跨域,他们都做了什么? 同源 vs 跨域 同源,字面意义是相同的源头,即同一个web服务器( ...

  10. ubuntu:undefined reference to `snd_pcm_open'

    这几天在做一个局域网的对讲机和广播系统. 需要用到alsa的库来进行音频采集和播放. 但是在编译程序的时候有个比较奇怪的问题. undefined reference to `snd_pcm_open ...