matlab白底换红底
白底换红底
局部阈值调整
边界高斯滤波
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白底换红底的更多相关文章
- Python给照片换底色(蓝底换红底)
环境要求 Python3 numpy函数库 opencv库 安装 下载适应版本的numpy函数库,我电脑是WIN10 64位,安装的函数库是 numpy-1.13.1+mkl-cp36-cp36m-w ...
- 用图来教你怎样用Photoshop蓝底转换红底
教你怎样用红底转换成蓝底.PS其实学了这个,你就可以在白底红底蓝底之间不同转变了. 第一步 第二步 第三步 第四步 最后给你们看看对比效果图
- 教你用OpenCV 和 Python给证件照换底色(蓝底 <->红底->白底)
在我们的生活中常常要用到各种底色要求的证件电子照,红底.蓝底.或者白底,而假如你手上只有一种底色的证件照,你又不想再去拍又不会PS怎么办?今天教你们用OpenCV和Python给你的证件照换底色. P ...
- MACD:黄白线、红绿柱与0轴关系
一.MACD的基本问题: (1)参数:统一用12,26,9 (2)MACD 位正.位不正原则 以下四种情况是黄白线.红绿柱与0轴关系的完全分类,行情出不了这四种情况, 即便黄白线在0轴单边反复缠绕 ...
- OpenCV实现彩色图像轮廓 换背景颜色
转摘请注明:https://i.cnblogs.com/EditPosts.aspx?opt=1 有时候我们需要不一样颜色的证件照,下面就用OpenCV来实现证件照的蓝底.红底等换颜色: 代码如下: ...
- 【PS】证件照转换背景色
证件照转换背景色 2019-07-14 12:18:49 by冲冲 1. 需求 自由切换证件照的背景颜色(白底.蓝底.红底...) 2. 步骤 ① 双击 图层锁 解锁,弹出的"新建图层0 ...
- Excel修改证件照图片背景色
在实际生活中,我们常常需要把白底证件照更改为蓝底或红底.操作步骤只需4步! 工具/原料 Excel 方法/步骤 第1步:插入白底证件照 单击[插入]---[图片],选择图片保存的位置, ...
- vue入门基础知识点测试
vue入门基础知识点测试 1.文本(值绑定){{var}}----控制<div></div>的值显示当前时间,且1秒更新一次.(可查阅 setinterval 函数,时间Dat ...
- [汇编语言]-第九章 在屏幕中间分别显示绿底红色,白底蓝色字符串"welcome to masm!"
;在屏幕中间分别显示绿色,绿底红色,白底蓝色字符串"welcome to masm!" assume cs:codesg,ds:datasg,ss:stacksg datasg s ...
随机推荐
- HTML5开发移动web应用—JQuery Mobile(1)
JQuery Mobile是一个简单易用的web移动app开发框架.使用它就像使用jQuery一样,引入必要的文件就可以. 最基础的jQuery Mobile文件的结构代码例如以下: <body ...
- 系统安全-PAM
Pluggable Authentication Modules(可插入验证模块,简称PAM) Linux-PAM(Pluggable Authentication Modules for Linux ...
- 腾讯云ubuntu memcached 安装
ubuntu安装 sudo apt-get install memcached 停止memcached服务:sudo systemctl stop memcached 激活memcached服务:s ...
- C++继承类同名数据成员被隐藏,其实都在内存里,转换后都可以被使用
#include "stdafx.h" class A { public: int i; A() { i=; } }; class B: public A { public: in ...
- 一起来学linux:PAM模块
在Linux中执行有些程序时,这些程序在执行前首先要对启动它的用户进行认证,符合一定的要求之后才允许执行,例如login, su等 在Linux中进行身份或是状态的验证程序是由PAM来进行的,PAM( ...
- 1 Maven简介
一.构建(build) 清理.编译.测试.打包.部署等一系列操作. 二.maven介绍: maven是一个强大的构建工具,能够帮助我们自动化构建过程:从清理(clean).编译(com ...
- Parallel Tests
Parallel Tests Parallel Android Tests Appium provides a way for users to automate multiple Android s ...
- self = [super init]的解释
在Object-C中我们很多时候都会重写init方法.一般情况下我们都会这样写: -(instancetype)initWithDic:(NSDictionary *)dic{ if(self=[su ...
- Ubuntu下安装Python3.4及用python编译py文件
1.安装python 3.4程序 sudo apt-get install python3.4 2.python 3.4是被默认安装在/usr/local/lib/python3.4,删除默认pyth ...
- Codeforces Round #383 (Div. 2) C. Arpa's loud Owf and Mehrdad's evil plan —— DFS找环
题目链接:http://codeforces.com/contest/742/problem/C C. Arpa's loud Owf and Mehrdad's evil plan time lim ...