How to obtain image intensity values of images

I want to obtain image intensity values at any three selected points of the original eight.tif image.

 Accepted Answer

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));

5 Comments

Also look up impixelinfo() if you want to display the intensity in real time as you mouse around over the image.
The code give me this error??
A=imread('eight.tif'); EDU>> imshow(A); EDU>> [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)); Undefined function 'grayImage' for input arguments of type 'int32'.
Moon, come on. If you're not going to call the image the descriptively-named "grayImage", and call it the badly-named "A" instead, then don't you think that when you pass the x and y indexes into an array to get the intensities, that you should use the name of your array? In other words, don't you think you should use "A" instead of "grayImage"???? Of course you should.
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 ?
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;
% Read in image.
fileName = 'eight.tif';
grayImage = imread(fileName);
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));

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!