How to include manual click control in imaging algorithm?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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);
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!