!7 // uses only one prototype image // goes through different granularities at once cmodule ImageRecogSpike { switchable S prototypeImageID = #1102884; switchable S inputImageID = #1102883; // how big do we think the prototype is in the whole image // (percentage by height) transient double assumedPrototypeHeightPercentage = 70; transient L widths = ll(32, 64, 128); transient new L integralImages; transient BWIntegralImage baseImage; transient JTabbedPane tabs = jTabbedPane(); transient BWImage prototypeImage; transient new L levels; // recognizers for each granularity class OneLevel extends SteppableAndBest { IBWIntegralImage ii; // scaled integral image BWImage image; // scaled image BWImage prototype; // scaled prototype float minSimilarity = 0.5f; ImageSurface is; *(IBWIntegralImage *ii) { image = iBWIntegralImageToBWImage(ii); // get assumed height of prototype in scaled-down image int ph = iround(ii.getHeight()*assumedPrototypeHeightPercentage/100.0); // resize prototype prototype = bwResizeToHeightSmooth(prototypeImage, ph); addTab(tabs, "proto " + ii.getWidth(), jFullCenterScroll(jPixelatedZoomedImageSurface(4.0, prototype))); } public bool step() { FoundImg fi = bwImageSearch_best(image, prototype, minSimilarity); print("Search result: " + fi); if (fi != null) { best.put(fi.r, fi.sim); setImageSurfaceSelection(is, best!); } false; // done } } start-thread { if (baseImage == null) baseImage = BWIntegralImage(loadImage2(inputImageID)); if (prototypeImage == null) prototypeImage = loadBWImage(prototypeImageID); for (int w : widths) { IBWIntegralImage ii = scaledIBWIntegralImage(baseImage, w); integralImages.add(ii); ImageSurface is = jPixelatedZoomedImageSurface( doubleRatio(baseImage.getWidth(), w), iBWIntegralImageToBWImage(ii)); addTab(tabs, "w=" + w, jFullCenterScroll(is)); levels.add(setAll(new OneLevel(ii), +is)); } addTab(tabs, "Prototype", jFullCenterScroll(jPixelatedZoomedImageSurface(4, prototypeImage))); time "Process" { for (OneLevel lvl : levels) lvl.step(); } } visual tabs; }