how to color circles on an image? the color should varies with the variation of the serial data

2 次查看(过去 30 天)
i have a microcontroller connected to a force sensor and sending serial data. i'm putting these data in a matrix i need to draw circles to represent the force sensors on an image and color them the color should varies with the values of the serial data. example if the value in the matrix is 46 the color of the circle should varies from blue to red could someone help me please

回答(3 个)

William Frane
William Frane 2014-8-1
A simple way to do this is to plot large circular data markers on top of the image (using the hold command). Something along the lines of:
% Display image
hold on
% Iterate through all the sensors
% Get position and color for each sensor
currentColor = ConvertValueToColor(currentSensorValue);
plot(currentX, currentY, 'Marker', 'o', 'MarkerSize', 30, 'MarkerFaceColor', currentColor, 'MarkerEdgeColor', 'none');
If you normalize your sensor data such that they lie between 0 and 1, you could use something like this to vary the color:
function out = ConvertValueToColor(in) % Picks a color between blue and red
% Assumes 'in' is between 0 and 1
out = (1-in)*[0 0 1] + in*[1 0 0];

Image Analyst
Image Analyst 2014-8-1
Another way is to use the rectangle() function to draw circles. Kind of crazy, but yes, rectangle() can draw circles(). I've always wondered why they just don't have a ellipse() or circle() function. But no, that would be too easy and intuitive.

marc kahwaji
marc kahwaji 2014-8-2
thanks for your help

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by