1
$\begingroup$

I want to create a snippet that shows an image with two locators, and side-by-side with its crop based upon the position of the locators. Here is what I wrote. But it gives error that the list of locator positions "is not valid region of interest."

How can I solve this error? And is there other simple way of realizing what I want?

img = Import["ExampleData/spikey.tiff"];
DynamicModule[{pts = {{1, 1}, {100, 100}}},
{LocatorPane[Dynamic[pts],img],ImageTrim[img,Dynamic[pts]]}]
$\endgroup$
2
$\begingroup$

Put Dynamic outside ImageTrim:

img = Import["ExampleData/spikey.tiff"];
DynamicModule[{pts = {{1, 1}, {100, 100}}},
  {LocatorPane[Dynamic[pts], img], Dynamic@ImageTrim[img, pts]}]

enter image description here

Introduction to Dynamic >> Where Should Dynamic Be Placed in an Expression:

  • Because Dynamic does its work entirely in the front end, you cannot use it inside functions that need to access the value of an expression in order to do their work.
  • Dynamic is a formatting function that does its work in the front end, not in the kernel, so if it is used in a way where it will never be placed as output, it is probably a mistake.
| improve this answer | |
$\endgroup$
  • $\begingroup$ Nice. Now I understand. $\endgroup$ – Chromatic Feb 20 '19 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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