How can I label each pixel of the output of IMAGESC with its value?

19 views (last 30 days)
I have drawn an image with the IMAGESC command and would like to label each pixel with its value.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The following code illustrates how this might be done:
% Generate Random Data
N = 5;
M = rand(N);
x = repmat(1:N,N,1); % generate x-coordinates
y = x'; % generate y-coordinates
% Generate Labels
t = num2cell(M); % extact values into cells
t = cellfun(@num2str, t, 'UniformOutput', false); % convert to string
% Draw Image and Label Pixels
imagesc(M)
text(x(:), y(:), t, 'HorizontalAlignment', 'Center')
  1 Comment
Image Analyst
Image Analyst on 16 Jun 2022
@RC here is what it looks like if there is a Nan:
% Generate Random Data
N = 5;
M = rand(N);
M(3,3) = nan;
x = repmat(1:N,N,1); % generate x-coordinates
y = x'; % generate y-coordinates
% Generate Labels
t = num2cell(M); % extact values into cells
t = cellfun(@num2str, t, 'UniformOutput', false); % convert to string
% Draw Image and Label Pixels
imagesc(M)
text(x(:), y(:), t, 'HorizontalAlignment', 'Center')
What do you want to see?

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2006b

Community Treasure Hunt

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

Start Hunting!