MATLAB Obsessive-compulsive disorder image generation

Source: Internet
Author: User

Recently popular network obsession photos do avatar, idle to Nothing, take Matlab get a builder, it can produce including 0-9 and 99+OCD.

The principle is very easy, the graph overlay, here in order to reduce the file, the digital picture is saved in the. MAT binary file.

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

The code is as follows:

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 widthheight = size (img,2);%image heightminlength = min ([width,height]);% Min of width and heightcircle_d = Floor (minlength* (1-0.618));%circle radiuscircle_x_end = Circle_d;circle_y_start = Heigh T-circle_d + 1;%circle centercircle_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)           and nbsp IMG (i,j,1) = 255;            img (i,j,2) = 0;            img (i, j,3) = 0;        end    endend% draw number-------------------------------load Number.matnu m = 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 imagevar_name = [' Number ' num2str (num)];eval ([var_name ' = Imresize (' Var_name ', [circle_x_end,height-circle_y_start+1]); %sharp the Imageeval ([' 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 layereval ([' 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 '; ']); Percent Show Imageimshow (IMG), percent save Imagedotindex = Max (Find (fn== ')); Imwrite (IMG,[FN (1:dotindex-1) ' with number ' num2str (num) fn (dotindex:end)]);

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

In addition, the binary files of the numbers are uploaded along with the code ( Click here to download )


For example, the following:







Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

MATLAB Obsessive-compulsive disorder image generation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.