• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

MATLAB在三维坐标中显示图片 并 使得图片部分透明

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

要画一个光路图,本来可以用proe,但是鼠标不好用,有些操作也忘了,用MATLAB画了个。下面是用到的图片。

但是三维坐标中显示彩色图片的目标没有搞定,做了个灰度图,然后用仿射程序将彩色图片贴到了二维灰度图中。


 

clear all;clc;close all;

im1 = rgb2gray(imread(\'F:\sup.jpg\'));% 掩模,第一张图,白色的部分在后面的surf中透明化了
im1 = imresize(im1,[64 64]);

im2 = rgb2gray(imread(\'F:\im3.jpg\'));% 样品,第二张图
im2(:,end) = [];
im2 = imresize(im2,[64,64]);
im2 = flipud(im2);


im3 = rgb2gray(imread(\'F:\diff.jpg\'));% 衍射图样,第三张图
im3(513:end,:) = [];
im3(:,513:end) = [];
im3 = flipud(im3);

% figure;
% subplot(121);imshow(im1);
% subplot(122);imshow(im4);
mask = PIEmask(256,200,128,128);
mask = imresize(mask,[64 64]);
%%
figure(\'color\',\'white\');

N = size(im3);
[x z] = meshgrid(-N/2:N/2-1);
y = 0*ones(N,N);
a = surf(x,y,z,  double(im3) );   % 画衍射图
set(a,\'linestyle\',\'none\');  %隐藏网格
colormap(gray);

hold on;
N = size(im2);
[x z] = meshgrid(-N/2:N/2-1);
y = -200*ones(N,N);
b = surf(x,y,z,  double(im2) );  % 画样品图
set(b,\'linestyle\',\'none\');  %隐藏网格
colormap(gray);

hold on;
N = size(im1);
[x z] = meshgrid(-N/2:N/2-1);
y = -210*ones(N,N);
% c = surf(x,y,z,  double(im1) );
c = surf(x,y,z,  double(im1),\'FaceAlpha\',\'flat\',\'AlphaDataMapping\',\'scaled\',\'AlphaData\',1-mask);  % 画掩模图,并将中间部分透明化
% alpha(0.5)
set(c,\'linestyle\',\'none\');  %隐藏网格
colormap(gray);
%%  后面的部分就是画红色的‘光’了
[yy zz] = meshgrid(-500:-210,-32:32);
xx = 32*ones(size(yy));

p = surf(xx,yy,zz,double(255*ones(size(zz))),\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.2*ones(size(zz)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格

p = surf(-xx,yy,zz,double(255*ones(size(zz))),\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.2*ones(size(zz)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格
%==========================================
[xx yy] = meshgrid(-32:32,-500:-210);
zz = 32.*ones(size(xx));

p = surf(xx,yy,zz,double(255*ones(size(zz))),\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.2*ones(size(zz)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格

p = surf(xx,yy,-zz,double(255*ones(size(zz))),\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.2*ones(size(zz)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格
%%
t = 0:0.01:2*pi;
x = 25*cos(t\');x = repmat(x,1,300);
z = 25*sin(t\');z = repmat(z,1,300);

y = linspace(-210,-200,300);
y = repmat(y,629,1);

p = surf(x,y,z,x*0,\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.5*ones(size(z)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格
%%
s1 = -25*sqrt(2)/2;
s2 = -256;
t1 = linspace(s1,s2,100);
x = [];
t2 = linspace(-s1,-s2,100);
for k = 1:100;
    tmp = (linspace(t1(k),t2(k),200))\';
    x = [x tmp];
end

y = linspace(-200,0,100);
y = repmat(y,200,1);
z = linspace(25*sqrt(2)/2,255,100);
z = repmat(z,200,1);

p = surf(x,y,z,x*0,\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.2*ones(size(z)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格

p = surf(x,y,-z,x*0,\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.2*ones(size(z)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格

p = surf(z,y,x,x*0,\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.15*ones(size(z)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格

p = surf(-z,y,x,x*0,\'FaceAlpha\',\'flat\',...
\'AlphaDataMapping\',\'scaled\',...
\'AlphaData\',0.15*ones(size(z)),...
\'FaceColor\',\'red\');
set(p,\'linestyle\',\'none\');  %隐藏网格
%%

grid off;
axis off;

view([150 -256 50]);
% view([150 -100 0]);
daspect([10,3,10]);%调节坐标轴比例

 效果如下

 

之后又用了个仿射程序把衍射图样彩色化了


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
mmz-asio4delphi死链接的解决办法发布时间:2022-07-18
下一篇:
Delphi2010新增功能之:TWICImage类[1]-方便的图像格式转换发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap