将图像映射成圆柱体或球体形状? [英] Mapping image into cylinder or sphere shape?
问题描述
所以我想说我有黑&使用imread()命令读取并保存到矩阵A中的白色图像。
So lets say I have black & white image that is read with imread() command and saved into matrix A.
我想输出/绘制此矩阵圆柱形图像。我知道如何在MATLAB中绘制圆柱体,但如果我想将图像放在圆柱体上或绘制圆柱形图像,我不知道应该怎么做。任何帮助将不胜感激。谢谢。
I want to output/graph this matrix A image in a cylinder shape. I know how to draw a cylinder in MATLAB, but I do not have a clue what I should do if I want to put image on a cylinder or draw image in cylinder shape. Any help will be appreciated. Thank you.
我通过谷歌搜索找到了这个网站。
http://www.flashandmath.com/advanced/rolls/cylin.html
这正是我想要做的,但我需要在MATLAB中这样做。
I found this site from googling. http://www.flashandmath.com/advanced/rolls/cylin.html This is exactly what I want to do, but I need to do this in MATLAB.
推荐答案
这项技术被称为纹理映射。这是 surface
函数(R2011b)的代码示例:
The technique is called texture mapping. This is a code example from surface
function (R2011b):
load clown
surface(peaks,flipud(X),...
'FaceColor','texturemap',...
'EdgeColor','none',...
'CDataMapping','direct')
colormap(map)
view(-35,45)
此示例从peppers.png加载RGB图像并将其映射到柱面上:
This example loads RGB image from "peppers.png" and maps it onto cylinder:
imgRGB = imread('peppers.png');
[imgInd,map] = rgb2ind(imgRGB,256);
[imgIndRows,imgIndCols] = size(imgInd);
[X,Y,Z] = cylinder(imgIndRows,imgIndCols);
surface(X,Y,Z,flipud(imgInd),...
'FaceColor','texturemap',...
'EdgeColor','none',...
'CDataMapping','direct')
colormap(map)
view(-35,45)
使用 natan 暗示的 warp
函数(图像处理工具箱附带)更简单:
Things are even simpler with the warp
function (comes with Image Processing toolbox) as natan suggested:
imgRGB = imread('peppers.png');
[imgRows,imgCols,imgPlanes] = size(imgRGB);
[X,Y,Z] = cylinder(imgRows,imgCols);
warp(X,Y,Z,imgRGB);
这篇关于将图像映射成圆柱体或球体形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!