7
$\begingroup$

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}]

Calculation of the mean value of multiple rgb values at 6 Locator positions 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]]},
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – m_goldberg
    Commented Feb 13, 2018 at 22:04
  • $\begingroup$ Thanks for the example. I tried in version 11, unfortunately it failed to create a region with the polygon. $\endgroup$
    – fathah
    Commented Jul 17, 2018 at 15:04

1 Answer 1

7
$\begingroup$
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, 
   Region`RegionCentroid[Polygon[pts[[FindShortestTour[pts][[-1]]]]]], Mean[pts]]]},
 {{pts, {{1, 1}}}, Locator, LocatorAutoCreate -> True}]

enter image description here

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.