matlab练习程序(渲染三原色)

栏目: 编程工具 · 发布时间: 5年前

内容简介:这里我用的空间是x向右为正,y向下为正,z向屏幕里面为正。相当于标准右手系绕x轴旋转了180度。将三个点光源放在r = [0.3,0,0.5];

这里我用的空间是x向右为正,y向下为正,z向屏幕里面为正。相当于标准右手系绕x轴旋转了180度。

将三个点光源放在

r = [0.3,0,0.5];

g = [0.3,-0.5*cos(pi/6),-0.5*sin(pi/6)];

b = [0.3,0.5*cos(pi/6),-0.5*sin(pi/6)];

这三个位置上,向四周发射光线,取光线到y-z平面的模的倒数作为光的强度。

图像如下:

matlab练习程序(渲染三原色)

程序如下:

clear all;
close all;
clc;

r = [0.3,0,0.5];
g = [0.3,-0.5*cos(pi/6),-0.5*sin(pi/6)];
b = [0.3,0.5*cos(pi/6),-0.5*sin(pi/6)];
imgr1=[];imgr2=[];
imgg1=[];imgg2=[];
imgb1=[];imgb2=[];
for y=-1:0.004:1
   imgr1=[];imgg1=[];imgb1=[];
   for z=-1:0.004:1       
       pm=[0,y,z];         
       lightr=pm-r;
       lightg=pm-g;
       lightb=pm-b;
       imgr=1/norm(lightr);
       imgg=1/norm(lightg);
       imgb=1/norm(lightb);
       
       imgr1=[imgr1 imgr];
       imgg1=[imgg1 imgg];      
       imgb1=[imgb1 imgb];           
   end
   imgr2=[imgr2;imgr1];
   imgg2=[imgg2;imgg1];  
   imgb2=[imgb2;imgb1]; 
end

[h w]=size(imgr2);

img=zeros(h,w,3);
img(:,:,1) = mat2gray(imgr2);
img(:,:,2) = mat2gray(imgg2);
img(:,:,3) = mat2gray(imgb2);
imshow(img)
imwrite(img,'img.png')

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Standards Creativity

Web Standards Creativity

Andy Budd、Dan Rubin、Jeff Croft、Cameron Adams、Ethan Marcotte、Andy Clarke、Ian Lloyd、Mark Boulton、Rob Weychert、Simon Collison、Derek Featherstone / friends of ED / March 19, 2007 / $49.99

Book Description * Be inspired by 10 web design lessons from 10 of the world's best web designers * Get creative with cutting-edge XHTML, CSS, and DOM scripting techniques * Learn breathtakin......一起来看看 《Web Standards Creativity》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具