How to obtain image intensity values of images
조회 수: 20 (최근 30일)
이전 댓글 표시
I want to obtain image intensity values at any three selected points of the original eight.tif image.
댓글 수: 0
채택된 답변
Image Analyst
2014년 2월 18일
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
Image Analyst
2014년 2월 18일
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));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!