Create an ImagePartition interface?

I am looking at creating an interface to select parts of an image after having applied ImagePartition. The idea is to select with the mouse from the ImagePartition result the parts of interest and then save each of them with a different name like partition number.

Would appreciate if anyone could help me on this as I am still new to wolfram language.

Hugues

Hi Hugh,

I am not sure if this is exactly what you want, but it might at least serve as a start:

ClearAll["Global`*"]

img =(* < your image > *)

imgMat0 = imgMat = ImagePartition[img, 64];

(* select (or unselect) image tiles with the mouse: *)
MatrixForm @ MapIndexed[PopupMenu[
    Dynamic[imgMat[[Sequence @@ #2]]], {imgMat[[Sequence @@ #2]], Framed[imgMat[[Sequence @@ #2]], FrameStyle -> {Red, Thick}]}] &, imgMat, {2}]

(* result: *)
selectedTiles = 
 Dynamic @ Complement[Flatten@imgMat0, Flatten@imgMat]

Regards – Henrik

Henrik,

Thank you for the example, I got it working fine but while saving the images it doesn’t separate them and always returns the entire selected file images (selectedTiles). This is strange as the export work well with any other set of images, so I am wondering if this is not due to the fact that selectedTiles is Dynamic?

…

file = FileNameJoin[{"/Users", "me", "Desktop", "Mathematica", "myfolder"]
Table[Export[
FileNameJoin[{file, StringJoin["myfile[", ToString[i], "].jpg"]}], 
selectedTiles[[i]], "JPEG"], {i, Length[selectedTiles}]

…

Copying the images and pasting them under a new variable (w/o the { }) works but obviously not the goal. :wink:

Hugh

Hi Hugh,

yes, you are right, the use of Dynamic causes here the problem:

selectedTiles // FullForm
(*  Out:  Dynamic[Complement[Flatten[imgMat0],Flatten[imgMat]]]  *)

so either you invoke single tiles writing:

First[selectedTiles][[i]]

or you just omit Dynamic and write:

selectedTiles = Complement[Flatten@imgMat0, Flatten@imgMat]

then it should work. Note that there are typos in you code, it should read:

file = FileNameJoin[{"/Users", "me", "Desktop", "Mathematica", "myfolder"}];
Table[Export[FileNameJoin[{file, StringJoin["myfile[", ToString[i], "].jpg"]}], 
  selectedTiles[[i]], "JPEG"], {i, Length[selectedTiles]}]

As a remark (my personal “taste”): Instead of using Table here I would use MapIndexed, like so:

MapIndexed[Export[FileNameJoin[{file, StringJoin["myfile[", ToString[First[#2]], "].jpg"]}], #1, "JPEG"] &, selectedTiles]

Regards – Henrik