白底换红底

局部阈值调整

边界高斯滤波

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. restframework-总结

    1. 规范 - 版本控制 - 部署专用的域名(防止跨域攻击) - 因为restframework又称为面向资源的编程所以url名词需要用专业的名词去表示 - 请求方式method - url上可以传递 ...

  2. python发送邮件相关问题总结

    一.发送邮件报错:554:DT:SPM 1.报错信息 2.通过查找163报错信息页面,554 DT:SPM的问题如下: 3.将邮件主题中的“test”去除,经过测试,实际上邮件主题包含“test”也能 ...

  3. MySQL安装过程中出现“APPLY security settings错误”的解决方式

    ***********************************************声明*************************************************** ...

  4. Spring 实战 学习笔记(1)

    Spring的核心 依赖注入 & 切面编程 1.创建应用组件之间协作的行为通常称为装配.(wiring) 2.Spring EL表达式.SEL是一种能在运行时构建复杂表达式,存取对象属性.对象 ...

  5. @GetMapping和@PostMapping接收参数的格式

    一.1.使用@Controller 注解,在对应的方法上,视图解析器可以解析return 的jsp,html页面,并且跳转到相应页面 若返回json等内容到页面,则需要加@ResponseBody注解 ...

  6. 解决访问google的问题

    我用的是360安全浏览器. 1.点击扩展,搜索goole 2.可以看到第一个就是谷歌访问助手 3.下载安装 4.点击永久激活之后它会提示你怎么做 5.大概是让你修改主页,修改主页是在选项里,第一个基本 ...

  7. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或

    题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...

  8. 一看就会,科目三靠边停车30cm技巧!再也不怕不会停车了!

    靠边停车是科目三考试的最后一关,如果在这一关失败,那之前所有的努力都功亏一篑了,你感觉吃不吃亏?就连我们自己平时开车,轮胎万一与路边石阶刮蹭,就会造成不小的伤害.那么靠边停车时有哪些注意要点呢?请和小 ...

  9. Java线程面试题 Top 50(转载)

    原文链接:http://www.importnew.com/12773.html 本文由 ImportNew - 李 广 翻译自 javarevisited 不管你是新程序员还是老手,你一定在面试中遇 ...

  10. 字符编码乱码问题(servlet底层 编码大揭秘)

    好多初学者会遇到,请求过去的信息内包含中文(一般会是get方式提交过去的请求会出现).好郁闷,这是为什么呢.有下面分析下,说的不好可以吐槽 话说我们能遇到这种编码的问题,归根结底就是这  这 web开 ...