How do i obtain a single pixel value in a grayscale image by clicking on it?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I have a GUI snd i need to obtain a pixel value of one of my images so i can set a threshold for segmentation. I only want one pixel value and want the user to click on the picture to find the specific value. Does ginput do this or is there something to ginput that i can use?
Accepted Answer
Image Analyst
on 23 Apr 2013
See my interactive thresholding app : http://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image. It should work beautifully for all type of grayscale images - let me know if it doesn't. Other than that, use ginput() to get the column,row coordinates
[column, row] = ginput(1);
grayLevel = image(row, column);
or use impixelinfo() to get the gray level "live" as you move the mouse around over the image.
7 Comments
Ryan
on 23 Apr 2013
Your app is fantastic! I am working on my project for a class, and mine is no where near that nice! I used the ginput and it gives me a column and row however when i grayLevel = image(row, column) i get an error that says "Incorrect number of arguments specified" and the image i have in the axis goes away. Any ideas on why that is?
Under my push button callback all i have is:
[column, row] = ginput(1); grayLevel = image(row, column)
and i dont get a pixel value.
Image Analyst
on 24 Apr 2013
Edited: Image Analyst
on 24 Apr 2013
Sorry - replace image with the actual name of your image variable, like img, grayImage, or whatever it's called. image is the name of a built in display function. ANd be sure to round row and column, or cast them to int32, because ginput() can give floating point (fractional) values. Maybe like this:
[x, y] = ginput(1);
row = int32(y);
column = int32(y);
grayLevel = grayImage(row, column);
% Or if it's an RGB image
rgbTriplet = rgbImage(row, column, :);
You can still do impixelinfo() - that's what I'd do instead of ginput(), but you can do both if you want.
Ryan
on 24 Apr 2013
But there are four images that can be clicked on so in the coding i wouldnt know which on the user picks. I am trying to make a GUI that finds fish. so i have four colored fish pictures, the user picks which one they want to find in the main image. when the user clicks the fish i want that to be the threshold which the segmentation is done around. Im just stuck on where on the part where i get pixel information from the users click. impixel works sometimes and sometimes i get NaN, is there any way i can get impixel to terminate after a single pixel has been chosen?
Image Analyst
on 24 Apr 2013
I think this is where you'd want to put the code in the mousedown event for each image, so you know which image they clicked on.
Ryan
on 24 Apr 2013
Okay so i just added a push button under each photo, when you pick one it pulls up ginput and i select a pixel, however when i use the code below i get a row and column but then get an error that says
Attempted to access BlueFish(91,212); index out of bounds because size(BlueFish)=[0,0]
mySize = size(BlueFish);
[column, row] = ginput(1); newRow = round(row); newColumn = round(column);
colorValue = BlueFish(newRow, newColumn);
Image Analyst
on 24 Apr 2013
Well, then you'd better track down why the BlueFish image is basically null.
Ryan
on 24 Apr 2013
I didnt have BlueFish set to global earlier in my program! That basically null comment clicked in my brain! Thank you so much for your help! I now have a set of RGB Values!
More Answers (0)
Categories
Find more on Basic Display in Help Center and File Exchange
Products
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)