Message Boards Message Boards

1
|
4721 Views
|
8 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Pick between two images thousands of times?

Posted 8 years ago

I need general guidance on how to set up an interactive application.

I have a large set of image pairs (thousands). My application needs to present each pair of images to the user and let them select one of the two images. I will later use both images for processing, but need to remember the user’s selection. Because of the large number of images it will probably be necessary to read each pair of images from disk for processing one at a time. They will all not fit in memory at one time. It is important that this application make the process of selecting images fast and accurate.

With a Manipulate command it is easy to present both images from a pair, and move from pair to pair. I have not found a way to make the selection between the two images in a Manipulate command. The process of moving between pairs is also slow.

Using a SetterBar with the images set as the buttons looks like a good way to present and process the choice between the image pair. I have not figured out how to apply this to large numbers of image pairs, and to save the user’s choice.

I need advice on how to structure this program. An example of a similar application would be very helpful.

Thanks

POSTED BY: Jeff Burns
8 Replies
Posted 8 years ago

How could this be done using Setterbar?

POSTED BY: Jeff Burns

You could do it very simple like this:

pairs = {Range[10], Range[10] + 10}\[Transpose];  (*here will be your data*)
i = 1;
max = Length[pairs];

chosen = ConstantArray[-1, max];
Dynamic[chosen]  (* interactively see your choice*)
Dynamic[pairs[[i]]] (* current pair *)
{Button["First", chosen[[i]] = 1; i = Clip[i + 1, {1, max}]], 
  Button["Second", chosen[[i]] = 2; i = Clip[i + 1, {1, max}]]} // Row

Of course you can do this much more advanced, using DynamicModule, Manipulate, et cetera...

If you want to load the data while it is evaluating:

LoadPairs[i_] := {i, i^2}
i = 1;
max = Length[pairs];

chosen = ConstantArray[-1, max];
Dynamic[chosen]
Dynamic[LoadPairs[i]]
{Button["First", chosen[[i]] = 1; i = Clip[i + 1, {1, max}]], 
  Button["Second", chosen[[i]] = 2; i = Clip[i + 1, {1, max}]]} // Row

or

LoadPairs[i_] := {i, i^2}
i = 1;
max = Length[pairs];

data = LoadPairs[i];
chosen = ConstantArray[-1, max];
Dynamic[chosen]
Dynamic[data]
Row@{
  Button["First", chosen[[i]] = 1; i = Clip[i + 1, {1, max}]; 
   data = LoadPairs[i];],
  Button["Second", chosen[[i]] = 2; i = Clip[i + 1, {1, max}]]; 
  data = LoadPairs[i];
  }
POSTED BY: Sander Huisman

The variable chosen is shown (but of course not necessary). chosen can be saved afterwards, or automatically after the last pair...

POSTED BY: Sander Huisman
Posted 8 years ago

I do not see how to eliminate the variable chosen.

POSTED BY: Jeff Burns
Posted 8 years ago

This was extremely helpful.

I made a few enhancements to this code.

{Button[Dynamic[LoadPairs[i][[1]]], chosen[[i]] = 1; i = Clip[i + 1, {1, max}], Background -> Dynamic[If[chosen[[i]] == 1, Red, White]]], Button[Dynamic[LoadPairs[i][[2]]], chosen[[i]] = 2; i = Clip[i + 1, {1, max}], Background -> Dynamic[If[chosen[[i]] == 2, Red, White]]], Button["Back", i = Clip[i - 1, {1, max}]], Button["Forward", i = Clip[i + 1, {1, max}]] } // Row

POSTED BY: Jeff Burns

Jeff,

Your application will interest many.

I can not comment much on the interactive setup part. To address the speed issue, you may want to Import batch of images in advance so that when a user makes a choice, the next pair of images is ready to be displayed.

POSTED BY: Matthias Odisio
Posted 8 years ago
getImagePair[fileNames_] := {Import[fileNames[[1]]], 
   Import[fileNames[[2]]]};

DynamicModule[
 {imagePair,
  pick} ,
 imagePair = getImagePair[FileNamesPaired[[1]]];
 {SetterBar[
   Dynamic[pick], {"a" ->  imagePair[[1]], "b" -> imagePair[[2]]}], 
  Dynamic[pick]}
 ]

I need to extend this code over a long list of files. Also need to save the value of “pick”.

POSTED BY: Jeff Burns

You might get better help if you post what you have tried so far.

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract