How to include manual click control in imaging algorithm?
Show older comments
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
Answers (2)
Bruno Pop-Stefanov
on 9 Oct 2014
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
on 9 Oct 2014
0 votes
Try me freehand drawing demos. One of them gives you the mean in a region you traced out over the image.
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!