Matlab產生強迫症圖片,

來源:互聯網
上載者:User

Matlab產生強迫症圖片,

最近網路上流行強迫症圖片做頭像,閑來無事,拿matlab弄了一個產生器,可以產生包含0-9以及99+的強迫症。

原理很簡單,可以直接用兩幅圖疊加,這裡為了減少檔案,將數字圖片儲存在.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 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 = height - 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)            img(i,j,1) = 255;            img(i,j,2) = 0;            img(i,j,3) = 0;        end    endend% draw number-------------------------------load number.matnum = 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 ';']);%% show imageimshow(img);%% save imagedotindex = max(find(fn=='.'));imwrite(img,[fn(1:dotindex-1) ' with number ' num2str(num) fn(dotindex:end)]);

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

另外數位二進位檔案隨代碼一起上傳在此(點擊此處下載)


如下:










聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.