Texture mapping with viscircles

1 回表示 (過去 30 日間)
James Murphy
James Murphy 2016 年 4 月 28 日
コメント済み: Image Analyst 2016 年 4 月 28 日
I am attempting to animate a half car model using Matlab. I am using the function viscircles to generate 2D circles which represent the wheels. Ideally I want to superimpose a downloaded image of a tyre onto this animation but 'cdata' is not a property of viscircles and when I use 'Color' an error message appears returning the color to be a 3 element vector.

回答 (1 件)

Image Analyst
Image Analyst 2016 年 4 月 28 日
viscircles() simply draw circles on your graph or image at the locations you specified.
You should be able to display circles in the specified color using the 'Color' input option, like this:
viscircles(centers,radii, 'Color', 'r');
so, what did you do that was different than this.
To display an image use imshow() or you can write to the cdata property of the axes - it has nothing at all to do with viscircles, just the axes. Something like (untested)
ax = gca;
ax.cdata = yourImage;
  2 件のコメント
James Murphy
James Murphy 2016 年 4 月 28 日
I have the viscircles command without assigning a color, but what I want do you is texture the circle's face with a specific jpeg. Using those axes commands returns the error message No public property cdata exists for class matlab.graphics.axis.Axes. I'm very new to animation so I don't fully understand assigning axes properties
Image Analyst
Image Analyst 2016 年 4 月 28 日
James, try this demo for a start.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
moonImage = imread('moon.tif');
subplot(2,3,1);
hImage1 = imshow(moonImage, [])
[rows1, columns1, numberOfColorchannels1] = size(moonImage);
axis on;
% Get handle to image inside axes.
theImage1 = hImage1.CData;
% Read in tire image.
tireImage = imread('tire.tif');
[rows2, columns2, numberOfColorchannels2] = size(tireImage);
subplot(2,3,2);
hImage2 = imshow(tireImage, [])
axis on;
% Get handle to image inside axes.
theImage2 = hImage2.CData;
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = columns2;
imageSizeY = rows2;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = columns2/2;
centerY = rows2/2;
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
subplot(2,3,3);
imshow(circlePixels);
axis on;
% Get tire in a circle maskmaskedTire = zeros(size(tireImage), 'uint8');
maskedTire = zeros(size(tireImage), 'uint8');
maskedTire(circlePixels) = tireImage(circlePixels);
% Now, display it.
subplot(2,3,4);
imshow(maskedTire);
axis on;
% Paste tire onto it at location 10, 50
upperLeftRow = 200
upperLeftCol = 100;
theImage1(upperLeftRow:upperLeftRow+rows2-1, upperLeftCol:upperLeftCol+columns2-1) = maskedTire;
hImage1.CData = theImage1;
% Now, display it.
subplot(2,3,4);
imshow(maskedTire);
axis on;

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by