# How to obtain image intensity values of images

42 views (last 30 days)
Moon Shadow on 17 Feb 2014
Commented: Image Analyst on 18 Feb 2014
I want to obtain image intensity values at any three selected points of the original eight.tif image.

Image Analyst on 18 Feb 2014
Try impixel() or just indexing
intensity1 = grayImage(y1, x1);
intensity2 = grayImage(y2, x2);
intensity3 = grayImage(y3, x3);
x and y are any INTEGER values that you want inside the boundaries of the image. If you need to user to select them, use ginput(3);
[x,y] = ginput(3); % User to select 3 points.
x = int32(x); % Round and cast to integer.
y = int32(y);
intensity1 = grayImage(y(1), x(1));
intensity2 = grayImage(y(2), x(2));
intensity3 = grayImage(y(3), x(3));
Moon Shadow on 18 Feb 2014
A=imread('eight.tif'); imshow(A); [x,y] = ginput(3); x = int32(x); y = int32(y); intensity1= A(y(1), x(1)); intensity2 = A(y(2), x(2)); intensity3 =A (y(3), x(3));
no any answer comes out ?
Image Analyst on 18 Feb 2014
I tried it and it worked fine. Are you saying that no intensity1, intensity2, and intensity3 were created? Did you look in the workspace panel for them? Here, here's the same code just fancied up a bit. See if it errors out or does not tell you the intensity values. It works fine for me.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
fileName = 'eight.tif';
imshow(grayImage);
axis on;
title(fileName, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
promptMessage = sprintf('Click on 3 points in the image,\nor click cancel to quit?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Let user click 3 points.
[x,y] = ginput(3)
% Plot those points over the image.
hold on;
plot(x, y, 'r+', 'MarkerSize', 40, 'LineWidth', 5);
% Convert to integers so we can get row and column indexes.
x = int32(x)
y = int32(y)
% Extract the gray level values from the pixels.
intensity1 = grayImage(y(1), x(1))
intensity2 = grayImage(y(2), x(2))
intensity3 = grayImage(y(3), x(3))
% Announce results.
message = sprintf('The intensity at (%d, %d) = %d.\nThe intensity at (%d, %d) = %d.\nThe intensity at (%d, %d) = %d.\n',...
x(1), y(1), intensity1, x(2), y(2), intensity2, x(3), y(3), intensity3);
uiwait(helpdlg(message));

### Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!