Average pixel values of several ROIs

11 views (last 30 days)
j
j on 30 Mar 2015
Edited: Image Analyst on 3 Apr 2015
I need to know how to calculate the average pixel value of a region of interest in an image (some images have several ROIs and I need to calculate the value for each of those ROI within an image). I used the Image Batch Processor from the Image Processing Toolbox (Matlab 2015a) to obtain masks containing my ROIs. I understand binary images to be the input image with 1s inside the ROI object h and 0s everywhere else, but I do not know how to use this information. I can use the Image Region Analyzer to access ROI properties, i.e. area, perimeter, etc., from the mask, but I do not know if this information is relevant to calculating the average pixel values of the ROI.
I know there is documentation online about how to do this for freehand ROIs, etc., but Matlab is brand new to me (without the Image Processing Toolbox, I would not have been able to detect my ROIs or to create the mask), so I am having trouble following the documentation, especially because I have a folder of binary images (the output of using the Image Batch Processor) and I am not defining my ROIs individually. Any help is greatly, greatly appreciated!

Accepted Answer

Guillaume
Guillaume on 30 Mar 2015
It's not clear whether your ROIs are in memory or just images on disk, but given a binary ROI image, and an input image of the same size, the mean of the pixels within the ROI is simply:
m = mean2(inputimage(logical(ROIimage)))
The logical(ROIimage) makes sure that the 0 and 1 of your ROI images are interpreted as logical (true / false). When you index an array (the inputimage here) with an array of logical it returns only the values of the original arrays for which the logicals are true (1). Hence, you only get the pixels within your ROI. mean2 is a function provided by the image processing toolbox and is just a shortcut to mean(A(:))

More Answers (1)

Image Analyst
Image Analyst on 30 Mar 2015
I don't know about that batch utility you're usingn, but it's certainly possible if you write your own program as illustrated in my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 which uses regionprops() to get the areas of all the ROI's at one time.
  4 Comments
Image Analyst
Image Analyst on 2 Apr 2015
Edited: Image Analyst on 3 Apr 2015
Attached is a new one. Evidently the handle graphics in R2015a don't like me using set() like that. I changed it to use the line() function instead of the stem() function and everything works fine now.
j
j on 2 Apr 2015
It works great. Thank you very much!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!