最近流行的网络迷恋的照片做头像,闲来无事,取matlab获取一个建设者,它可以产生包括0-9以及99+OCD。

原理很easy,图叠加,这里为了降低文件,将数字图片保存在.mat二进制文件里。

=====================================================================================================

代码例如以下:

clear,clc
%% open image file
[fn,pn,fi]=uigetfile('*.bmp;*.png;*.jpg;*.jpeg','choose image');
img=imread([pn fn]);
%% process image 
width = size(img,1);%image width
height = size(img,2);%image height
minlength = min([width,height]);%min of width and height
circle_d = floor(minlength*(1-0.618));%circle radius
circle_x_end = circle_d;
circle_y_start = height - circle_d + 1;
%circle center
circle_center_x = circle_x_end/2;
circle_center_y = (circle_y_start+height)/2;
%draw circle--------------------------------
for i=1:circle_x_end
    for j=circle_y_start:height
        if((i-circle_center_x)^2+(j-circle_center_y)^2 <= (circle_d/2)^2)
            img(i,j,1) = 255;
            img(i,j,2) = 0;
            img(i,j,3) = 0;
        end
    end
end
% draw number-------------------------------
load number.mat
num = input('Input the number to add to the image:');
while(num<0 || num>9)
    num = input('Input error,out of range(0-9),reinput the number:'); 
end
%-------------------------------------------
%scale the nu7mber image
var_name = ['number' num2str(num)];
eval([var_name '=imresize(' var_name ',[circle_x_end,height - circle_y_start+1]);']);
%sharp the image
eval(['index = find(' var_name '>0);']);
for k=1:length(index)
    eval([var_name '(index(k)) = 255;']);
end
%add the value to the 2nd and 3rd layer
eval(['img(1:circle_x_end,circle_y_start:height,2) = img(1:circle_x_end,circle_y_start:height,2)+' var_name ';']);
eval(['img(1:circle_x_end,circle_y_start:height,3) = img(1:circle_x_end,circle_y_start:height,3)+' var_name ';']);
%% show image
imshow(img);
%% save image
dotindex = max(find(fn=='.'));
imwrite(img,[fn(1:dotindex-1) ' with number ' num2str(num) fn(dotindex:end)]);

=====================================================================================================

另外数字的二进制文件随代码一起上传在此(点击此处下载

效果图例如以下:

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Matlab强迫症产生的图像的更多相关文章

  1. matlab之原始处理图像几何变换

    (一)图像几何变换理论知识 (1)图像的平移与比例 图像的平移很简单,平移前后的坐标分别为(x,y)和(x',y'),则满足的关系式为 x'= x +Tx: y'= y +Ty: 其中Tx与Ty分别为 ...

  2. matlab练习程序(图像球面化)

    十一没什么事干,接着看图像算法. 这个球面化算法最初是在ps上的球面化滤镜中看到的,感觉挺有意思,就研究了一下. 算法的详细推导可以在这篇博客中找到,我比较懒,只在纸上推了一遍,就不在博客上编辑了. ...

  3. matlab各类数据l图像之间的转化

    matlab各类数据图像之间的转化 rgb类型转化为二值的步骤例如以下: 1.採用命令im2double将rgb类型转化三维的double >> str='E:\programing\Ei ...

  4. matlab学习笔记,图像分块

    clc; clear all; close all; I = imread('E:\matlab\files-images\tomsen512.jpg'); rs = size(I, 1);% 行数c ...

  5. MATLAB解析PFM格式图像

    http://www.p-chao.com/ja/2016-09-27/matlab%E8%A7%A3%E6%9E%90pfm%E6%A0%BC%E5%BC%8F%E5%9B%BE%E5%83%8F/ ...

  6. Matlab图像处理系列4———图像傅立叶变换与反变换

    注:本系列来自于图像处理课程实验.用Matlab实现最主要的图像处理算法 1.Fourier变换 (1)频域增强 除了在空间域内能够加工处理图像以外.我们还能够将图像变换到其它空间后进行处理.这些方法 ...

  7. matlab练习程序(图像投影到点云)

    最近接触点云比较多,如果把图像投影到点云应该挺有意思. 首先需要载入图像,然后做个球或其他什么形状的点云,这里可以参考球坐标公式. 最后通过pcshow将像素输出到点云上即可. 原图: 投影后的点云: ...

  8. matlab 视频转换到图像并保存

    图像处理中像Adas.车辆检测等都需要采用视频文件比较好处理一点,利用帧差法.背景减法.光流法等,那么将视频文件转换到图像文件怎么做呢?话不多说,见代码一目了然: %================= ...

  9. matlab练习程序(图像马赛克)

    处理原理就是将邻域像素平均值赋给邻域中的所有像素. 这里将处理方法分为了带线条和不带线条,带线条处理后的视觉效果要好些. 原图: 处理结果(不带线条): 处理结果(带线条): 代码处理的是带线条的情况 ...

随机推荐

  1. POJ 2418 Hardwood Species( AVL-Tree )

    #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> ...

  2. vim经常使用命令总结

    vim 选择文本,删除,复制,粘贴   文本的选择,对于编辑器来说,是非常主要的东西,也常常被用到,总结例如以下: v    从光标当前位置開始,光标所经过的地方会被选中,再按一下v结束. V     ...

  3. java中super()和this()浅析

    <span style="font-size:18px;">本质:这两个都是调用构造方法的方法.</span> 在java中,super()是在当前类的构造 ...

  4. Python编程中常用的12种基础知识总结

    原地址:http://blog.jobbole.com/48541/ Python编程中常用的12种基础知识总结:正则表达式替换,遍历目录方法,列表按列排序.去重,字典排序,字典.列表.字符串互转,时 ...

  5. wkhtmtopdf--高分辨率HTML转PDF(一)

    原文:wkhtmtopdf--高分辨率HTML转PDF(一) 一.需求 这次工作中遇到一个需求,要求把网页转换为PDF,穷极了很多的方法,包括尝试了itextsharp来转换,虽然可以实现,但是分辨率 ...

  6. Cocos3d初探

    预计要相当长的一段时间内研究游戏引擎,在这里做一下过程中的备忘. 上一周项目须要,研究了一下cocos2d-x,本周接着来做cocos3d-x的代码研究 首先是搭建cocos3d-x的开发环境: 依据 ...

  7. tomcat 下部署 php

    由于需要测试一个PHP的环境.故记录此处. 环境 OS:win8.1 up1 64bit tomcat :8.0.14 64bit php:php-5.6.2-Win32-VC11-x64.zip 将 ...

  8. Note for video Machine Learning and Data Mining——Linear Model

    Here is the note for lecture three. the linear model Linear model is a basic and important model in ...

  9. 浅谈JAVA ThreadPoolExecutor(转)

    这篇文章分为两部分,前面是ThreadPoolExecutor的一些基本知识,后一部分则是Mina中一个特殊的ThreadPoolExecutor代码解析.算是我的Java学习笔记吧. 基础 在我看来 ...

  10. SVN更改登录用户(转)

    一) 原地址:http://www.ixna.net/articles/2606 //证书缓存 $ svn list https://host.example.com/repos/project Er ...