How can I label each pixel of the output of IMAGESC with its value?
19 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: Image Analyst
on 16 Jun 2022
I have drawn an image with the IMAGESC command and would like to label each pixel with its value.
Accepted Answer
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
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?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!