2
$\begingroup$

I want to segment an arrayplot donut in to 6 pizza slices and export per segment the coordinates and intensity values of the pixels inside of it.

I found a good example, which used RegionMember to exclude data points from a listplot.

code used from thread

Exclude data from a list (kguler)

How to check if a 2D point is in a polygon? (aisamu)

data = Table[{RandomReal[{-10, 10}], RandomReal[{-10, 10}]}, {i, 1, 
    10}];
L0 = ListPlot[data, Frame -> True, Axes -> False, AspectRatio -> 1, 
   ImageSize -> 400, BaseStyle -> PointSize[.02]];

Deploy@DynamicModule[{list = {}}, Row[{EventHandler[

 Dynamic[
  Show[L0, 
   Graphics[{Opacity[.4], Yellow, EdgeForm[Thick], Polygon[list], 
     Purple, PointSize[.03], Point[list]}, 
    PlotRange -> PlotRange[L0]]]], {"MouseDown" :> 
   AppendTo[list, MousePosition["Graphics"]]}],


Dynamic@
 ListPlot[
  If[Length@list <= 2, data, 
   Pick[data, ! RegionMember[Polygon@list, #] & /@ data]], 
  BaseStyle -> PointSize[.02], Axes -> False, L0[[2]], 
  Prolog -> {Opacity[.5], Yellow, Polygon[list]}]}, Spacer[5]]]

enter image description here

So i tried to use the same code for my array plot (code below), but it is not working. It does not select the arraypixels (coordiantes and value) inside the red area, as you can see in the right arrayplot on the image below. It only gives a realvalue error and and i dont know how to fix it.

I also wonder if its possible to segment multiple regions like i did in paint.

data1 = bla2[[9]];
L01 = ArrayPlot[data1, Frame -> True, Mesh -> True, AspectRatio -> Automatic, ImageSize -> 400];

Deploy@DynamicModule[{list = {}}, Row[{EventHandler[

 Dynamic[
  Show[L01, 
   Graphics[{Opacity[.3], Red, EdgeForm[Thin], Polygon[list], Red,
      PointSize[.01], Point[list]}, 
    PlotRange -> PlotRange[L01]]]], {"MouseDown" :> 
   AppendTo[list, MousePosition["Graphics"]]}],


Dynamic@ArrayPlot[
 If[Length@list <= 2, data1, 
  Pick[data1, ! RegionMember[Polygon@list, #] & /@ data1]], 
 BaseStyle -> PointSize[.02], Axes -> False, L01[[2]], 
 ImageSize -> 300, 
 Prolog -> {Opacity[.5], Yellow, Polygon[list]}]}, Spacer[5]]]

enter image description here

I hope some one can help me out

Edit, Maybe you have a better method in mind. I would love to hear.

$\endgroup$
2
  • $\begingroup$ In the code sample you're using the data is a set of coordinates, while in your code is an array of values, quite different. I suggest going back to the design board. $\endgroup$ Nov 11, 2014 at 12:48
  • $\begingroup$ I see, i think it is possible to get the coordinates for each pixel in the arrayplot and use that as data set to draw the segments. And then link the coordinates from the segment region back to the intensity values. $\endgroup$
    – Eib
    Nov 11, 2014 at 13:24

0

Your Answer

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

Browse other questions tagged or ask your own question.