4
$\begingroup$

I'm switching over Matlab, but I have a problem. Matlab has a GUI tool called the "Training Image Labeler" (shown below) that I use all the time to label my training data for my computer vision related work:

enter image description here

It's simple, you just drag rectangles (with a fixed asset ratio) over each of the regions of the images that you need to label and then it neatly generates an xml file that has a list of the bounding boxes per filename. How can I accomplish this in Mathematica? This is a standard a common need.

Right now I'm looking at the image tool in version 10, but I don't see any batch labeling functionality.

$\endgroup$
3
  • $\begingroup$ I tried to export/import them but MMA is not importing .mat file. Import["/Users/tom/labelingSession.mat", "LabeledData"] -> Import::unsup: Unsupported type of MAT file. >> $\endgroup$ Commented Feb 26, 2015 at 23:07
  • 1
    $\begingroup$ If it generates a neat XML file, why not simply import that into Mathematica? $\endgroup$
    – C. E.
    Commented Feb 27, 2015 at 8:55
  • 1
    $\begingroup$ Because I want to discontinue my license and switch to mathematica @Pickett $\endgroup$ Commented Feb 27, 2015 at 14:00

2 Answers 2

1
$\begingroup$

You can achieve almost the same thing by saving coordinates. Place an image in Mathematica, click on it, and choose the "coordinates tool" form the little popup menu. Click on as many points as you want (say the upper left and lower right of a bounding box, if that's what you want). When done, choose "copy coordinates". Then paste them into a list.

$\endgroup$
4
  • $\begingroup$ @bill_s This works for a single image, but this is not efficient at scale. I have hundreds of images so I'm not going to import each one and then do this all inline by hand, need to automate the process, you know? $\endgroup$ Commented Feb 27, 2015 at 1:39
  • $\begingroup$ But aren't you doing it by hand in Matlab? Anyway, your problem with .mat import -- it will work for simple matrices, so you may have more complex data structures that don't import well. There is also Matlink (matlink.org) that may be able to handle the communication. $\endgroup$
    – bill s
    Commented Feb 27, 2015 at 1:59
  • $\begingroup$ @bill_s Looks like it's not possible now... I'll probably end up making a tool and posting the code. $\endgroup$
    – M.R.
    Commented Feb 27, 2015 at 2:55
  • $\begingroup$ Does mathematica.stackexchange.com/a/271156/74641 work for you? I have a couple issues running it. It could be fixed up and enforce 1:1 rectangles. $\endgroup$
    – Adam
    Commented Aug 25, 2023 at 5:23
1
$\begingroup$

If you're just looking for faces, mma has the built in FindFaces function:

img = Import["https://i.sstatic.net/A7aPb.png"];
box = FindFaces[img];
HighlightImage[img, box]

Mathematica graphics

The bounding boxes are formatted as Rectangles:

box
(*{Rectangle[{235.5, 217.5}, {322.5, 321.5}], 
 Rectangle[{178.5, 304.5}, {233.5, 381.5}], 
 Rectangle[{281.5, 334.5}, {339.5, 405.5}], 
 Rectangle[{344.5, 273.5}, {420.5, 362.5}], 
 Rectangle[{91.5, 220.5}, {169.5, 315.5}], 
 Rectangle[{176.5, 182.5}, {253.5, 267.5}], 
 Rectangle[{445.5, 273.5}, {516.5, 372.5}]}*)

For other non-face things, you can use ImageBoundingBoxes

$\endgroup$

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