How to include manual click control in imaging algorithm?

1 回表示 (過去 30 日間)
Alexander
Alexander 2014 年 10 月 8 日
回答済み: Image Analyst 2014 年 10 月 9 日
Hello, I am trying to create a program where after I load an image and display it, I can manually click on the image and return the pixel intensity values in a defined kernel. Please help me understand how to implement this click control and specify the shape of the kernel. cheers

回答 (2 件)

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 10 月 9 日
You can use ginput to select a pixel from an image displayed in an axes. ginput returns the x and y coordinates of the location where the user clicked. You can use these coordinates to get the intensity value at that location.
For example:
1. Read image in
I = imread('coins.png');
2. Display image
figure
imagesc(I)
colormap(gray)
3. Ask the user to select 1 point
[x,y] = ginput(1);
4. Round the coordinates to the nearest pixel
x = round(x);
y = round(y);
5. Return the intensity value at that location
intensityValue = I(y,x)
As for defining kernels, I am not sure what you mean. Do you mean that you would like to define a region in an image using the mouse?
If yes, then you can use the roipoly function to draw a polygon in the image. The function returns the region as a binary mask. You can then use this mask to get the average intensity over the specified region.
For example:
1. Read image in
I = imread('coins.png');
2. Display image
figure
imagesc(I)
colormap(gray)
3. Ask the user to draw a polygon in the image
mask = roipoly;
4. Get all the intensity values for the specified region
intensityValues = I(mask);
5. Compute the mean of these values
averageIntensityValue = mean(intensityValues);

Image Analyst
Image Analyst 2014 年 10 月 9 日
Try me freehand drawing demos. One of them gives you the mean in a region you traced out over the image.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by