# Mean RGB value of a locator region?

i am working at a color deconvolution using Ruifrok and Johnston's method (as described here).

To get a custom stain, I need to realize a vector with mean RGB values of a region in a given image. So far I worked with the mean RGB value of multiple locators using a locator pane and auto-create, but I am wondering if there is a function I didn't see to let the user select a whole region and calculate the mean RGB value for that chosen region.

I hope anybody can give me a hint.

Edit:

I am adding an excerpt of my code to concretise my problem.

Manipulate[Column@{Show[z], u = ImageValue[z, Mean[pts]]},
{{pts, {{1, 1}}}, Locator, LocatorAutoCreate -> True}]


As you can see I am calculating the mean value of 6 locator image values. Instead I want to achieve a calculation of a whole area. For example the user sets 4 Locators and the area between them is used for this calculation. Or is there an implemented function in Mathematica?

Edit 2:

  Manipulate[Column@{Show[z, Graphics[{EdgeForm[Thick], Opacity[0, White],
pol = Polygon[pts]}]], u = ImageValue[z, Mean[pts]]}, {{pts, {{1, 1}}},
Locator, LocatorAutoCreate -> True}]


I continued my work and had the idea of using "ImageMeasurement" combined with masking but unfortunately I cannot use a transparent white polygon acting as the mask to convolve

{Button["Measure", ImageMeasurements[z, "Mean", Masking -> pol]]},

• Your question needs to supply more information of exactly what you are trying accomplish. Editing your question by adding the code you currently using would probably be the best way to inform us. – m_goldberg Feb 13 '18 at 22:04
• Thanks for the example. I tried in version 11, unfortunately it failed to create a region with the polygon. – fathah Jul 17 '18 at 15:04

z= Import["http://www.mecourse.com/landinig/software/cdeconv/tric.png"];

Manipulate[Column@{Show[z, Graphics[{Opacity[.3, Yellow],
Polygon[pts[[FindShortestTour[pts][[-1]]]]]}], ImageSize->400],
u = ImageValue[z, If[Length@pts >= 3,
RegionRegionCentroid[Polygon[pts[[FindShortestTour[pts][[-1]]]]]], Mean[pts]]]},
{{pts, {{1, 1}}}, Locator, LocatorAutoCreate -> True}]


This works as is in version 9. In versions 10+, you can use RegionCentroid in place of RegionRegionCentroid.

• That should be exactly what i was looking for. Thanks for your help. Going to have look at it right now. – blackcore Feb 14 '18 at 2:36
• @kglr why did you use RegionRegionCentroid? – user5601 Feb 14 '18 at 4:17
• @user5601, if you mean why not just RegionCentroid`, I am still on version 9. – kglr Feb 14 '18 at 4:37