Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping image into cylinder or sphere shape?

So lets say I have black & white image that is read with imread() command and saved into matrix A.

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.

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.

like image 211
J L Avatar asked Jan 13 '23 10:01

J L


1 Answers

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)

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)

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);
like image 83
anandr Avatar answered Jan 21 '23 20:01

anandr