Changeset 33458


Ignore:
Timestamp:
2019-09-07T14:30:32+12:00 (5 years ago)
Author:
cpb16
Message:

Running new morphology version after quick meeting with david last week. init tests are looking good. Running on whole corpus now...

Location:
other-projects/is-sheet-music-encore/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • other-projects/is-sheet-music-encore/trunk/EndToEndSystem.sh

    r33455 r33458  
    3737if [ $type == "morph" ] ; then
    3838    if [ $# != 2 ] ; then
    39         echo "Usage:./EndToEndSystem cluster <ResultSubDirectory>"
     39        echo "Usage:./EndToEndSystem cluster <ResultSubDirectory> "
    4040        exit 1
    4141    fi
    4242    location=$2
     43
    4344    #Compile
    4445    echo "Compiling java programs..."
  • other-projects/is-sheet-music-encore/trunk/Makefile

    r33449 r33458  
    2828   
    2929run-morphology-20-test:
    30     cd image-identification-terminal/log-all-hires-new/test; rm log-morphology-MU-test.txt
     30    cd image-identification-terminal/log-all-hires-new/test; rm *.txt
    3131    cd image-identification-terminal; javac javaAccuracyCalculator.java
    3232    cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java;
  • other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/.idea/workspace.xml

    r33455 r33458  
    1515        <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java">
    1616          <provider selected="true" editor-type-id="text-editor">
    17             <state relative-caret-position="677">
     17            <state relative-caret-position="557">
    1818              <caret line="779" column="12" selection-start-line="779" selection-start-column="12" selection-end-line="779" selection-end-column="12" />
    1919              <folding>
     
    4040        <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java">
    4141          <provider selected="true" editor-type-id="text-editor">
    42             <state relative-caret-position="144">
    43               <caret line="1217" column="16" selection-start-line="1217" selection-start-column="16" selection-end-line="1217" selection-end-column="16" />
     42            <state relative-caret-position="383">
     43              <caret line="236" column="54" selection-start-line="236" selection-start-column="54" selection-end-line="236" selection-end-column="54" />
    4444              <folding>
    4545                <element signature="imports" expanded="true" />
    46                 <element signature="class#Pair#0;class#MainMorph#0" />
    4746                <element signature="method#imageViewer#0;class#MainMorph#0" />
    48                 <element signature="e#13990#16460#1" />
    49                 <element signature="e#16545#18548#1" />
    50                 <element signature="e#18617#21240#1" />
    51                 <element signature="e#21324#26995#1" />
    52                 <element signature="e#27080#31057#1" />
    53                 <element signature="e#31125#32303#1" />
    54                 <element signature="e#32372#36335#1" />
    55                 <element signature="e#36445#48148#1" />
    56                 <element signature="e#42969#43036#0" />
    57                 <element signature="e#48242#59125#1" />
     47                <element signature="e#14232#16729#1" />
     48                <element signature="e#16814#18826#1" />
     49                <element signature="e#18895#21536#1" />
     50                <element signature="e#21620#27308#1" />
     51                <element signature="e#27393#31396#1" />
     52                <element signature="e#31464#32641#1" />
     53                <element signature="e#32710#36690#1" />
     54                <element signature="e#36800#48520#1" />
     55                <element signature="e#45567#45616#0" />
     56                <element signature="e#48614#59515#1" />
     57                <element signature="e#59847#68195#1" />
     58                <element signature="e#61117#61159#0" />
    5859              </folding>
    5960            </state>
     
    6465        <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java">
    6566          <provider selected="true" editor-type-id="text-editor">
    66             <state relative-caret-position="1539">
    67               <caret line="135" column="4" selection-start-line="135" selection-start-column="4" selection-end-line="160" selection-end-column="5" />
     67            <state relative-caret-position="225">
     68              <caret line="592" column="12" selection-start-line="592" selection-start-column="12" selection-end-line="592" selection-end-column="12" />
    6869              <folding>
    6970                <element signature="imports" expanded="true" />
     
    7172                <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" />
    7273                <element signature="class#Pair#0;class#javaClassifierComparison#0" />
     74                <element signature="method#main#0;class#javaClassifierComparison#0" />
    7375                <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" />
    7476                <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" />
     
    107109        <option value="$PROJECT_DIR$/../image-identification-terminal/javaImageClassifier.java" />
    108110        <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison" />
     111        <option value="$PROJECT_DIR$/image-identification-development/src/Main.java" />
    109112        <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java" />
    110         <option value="$PROJECT_DIR$/image-identification-development/src/Main.java" />
    111113        <option value="$PROJECT_DIR$/image-identification-development/src/MainMorph.java" />
    112114      </list>
     
    120122  </component>
    121123  <component name="ProjectFrameBounds" extendedState="6">
    122     <option name="x" value="511" />
    123     <option name="y" value="214" />
    124     <option name="width" value="918" />
    125     <option name="height" value="767" />
     124    <option name="x" value="67" />
     125    <option name="y" value="25" />
     126    <option name="width" value="807" />
     127    <option name="height" value="1025" />
    126128  </component>
    127129  <component name="ProjectView">
     
    189191      <window_info anchor="bottom" id="Message" order="0" />
    190192      <window_info anchor="bottom" id="Find" order="1" weight="0.32962137" />
    191       <window_info anchor="bottom" id="Run" order="2" weight="0.27951002" />
     193      <window_info anchor="bottom" id="Run" order="2" weight="0.42316258" />
    192194      <window_info anchor="bottom" id="Debug" order="3" weight="0.3997773" />
    193195      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
     
    234236      </provider>
    235237    </entry>
    236     <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java">
    237       <provider selected="true" editor-type-id="text-editor">
    238         <state relative-caret-position="1539">
    239           <caret line="135" column="4" selection-start-line="135" selection-start-column="4" selection-end-line="160" selection-end-column="5" />
    240           <folding>
    241             <element signature="imports" expanded="true" />
    242             <element signature="method#init#0;class#javaClassifierComparison#0" />
    243             <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" />
    244             <element signature="class#Pair#0;class#javaClassifierComparison#0" />
    245             <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" />
    246             <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" />
    247             <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" />
    248             <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" />
    249             <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" />
    250             <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" />
    251             <element signature="method#removeDuplicates#0;class#javaClassifierComparison#0" />
    252             <element signature="method#VarianceCalc#0;class#javaClassifierComparison#0" />
    253             <element signature="method#lineComparison#0;class#javaClassifierComparison#0" />
    254             <element signature="method#ClusterCheck#0;class#javaClassifierComparison#0" />
    255           </folding>
    256         </state>
    257       </provider>
    258     </entry>
    259238    <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java">
    260239      <provider selected="true" editor-type-id="text-editor">
    261         <state relative-caret-position="677">
     240        <state relative-caret-position="557">
    262241          <caret line="779" column="12" selection-start-line="779" selection-start-column="12" selection-end-line="779" selection-end-column="12" />
    263242          <folding>
     
    280259      </provider>
    281260    </entry>
    282     <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java">
     261    <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java">
    283262      <provider selected="true" editor-type-id="text-editor">
    284         <state relative-caret-position="144">
    285           <caret line="1217" column="16" selection-start-line="1217" selection-start-column="16" selection-end-line="1217" selection-end-column="16" />
     263        <state relative-caret-position="225">
     264          <caret line="592" column="12" selection-start-line="592" selection-start-column="12" selection-end-line="592" selection-end-column="12" />
    286265          <folding>
    287266            <element signature="imports" expanded="true" />
    288             <element signature="class#Pair#0;class#MainMorph#0" />
    289             <element signature="method#imageViewer#0;class#MainMorph#0" />
    290             <element signature="e#13990#16460#1" />
    291             <element signature="e#16545#18548#1" />
    292             <element signature="e#18617#21240#1" />
    293             <element signature="e#21324#26995#1" />
    294             <element signature="e#27080#31057#1" />
    295             <element signature="e#31125#32303#1" />
    296             <element signature="e#32372#36335#1" />
    297             <element signature="e#36445#48148#1" />
    298             <element signature="e#42969#43036#0" />
    299             <element signature="e#48242#59125#1" />
     267            <element signature="method#init#0;class#javaClassifierComparison#0" />
     268            <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" />
     269            <element signature="class#Pair#0;class#javaClassifierComparison#0" />
     270            <element signature="method#main#0;class#javaClassifierComparison#0" />
     271            <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" />
     272            <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" />
     273            <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" />
     274            <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" />
     275            <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" />
     276            <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" />
     277            <element signature="method#removeDuplicates#0;class#javaClassifierComparison#0" />
     278            <element signature="method#VarianceCalc#0;class#javaClassifierComparison#0" />
     279            <element signature="method#lineComparison#0;class#javaClassifierComparison#0" />
     280            <element signature="method#ClusterCheck#0;class#javaClassifierComparison#0" />
    300281          </folding>
    301282        </state>
    302283      </provider>
    303284    </entry>
     285    <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java">
     286      <provider selected="true" editor-type-id="text-editor">
     287        <state relative-caret-position="383">
     288          <caret line="236" column="54" selection-start-line="236" selection-start-column="54" selection-end-line="236" selection-end-column="54" />
     289          <folding>
     290            <element signature="imports" expanded="true" />
     291            <element signature="method#imageViewer#0;class#MainMorph#0" />
     292            <element signature="e#14232#16729#1" />
     293            <element signature="e#16814#18826#1" />
     294            <element signature="e#18895#21536#1" />
     295            <element signature="e#21620#27308#1" />
     296            <element signature="e#27393#31396#1" />
     297            <element signature="e#31464#32641#1" />
     298            <element signature="e#32710#36690#1" />
     299            <element signature="e#36800#48520#1" />
     300            <element signature="e#45567#45616#0" />
     301            <element signature="e#48614#59515#1" />
     302            <element signature="e#59847#68195#1" />
     303            <element signature="e#61117#61159#0" />
     304          </folding>
     305        </state>
     306      </provider>
     307    </entry>
    304308  </component>
    305309  <component name="masterDetails">
  • other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/MainMorph.java

    r33455 r33458  
    226226            //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-8.png";      //Handwritten
    227227            //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-9.png";      //Handwritten
    228             String default_file = hiresDirectory+"/MU/SheetMusic/coo.31924062612282-9.png";           //Snippet
     228            //String default_file = hiresDirectory+"/MU/SheetMusic/coo.31924062612282-9.png";           //Snippet
    229229            //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-10.png";   //Generated
    230230            //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-7.png";
     
    235235            //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-2.png";  //large numbers
    236236            //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-3.png";
     237            String default_file = hiresDirectory+"/MU/SheetMusic/mdp.39015080921409-9.png";
    237238            //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-4.png";
    238239            //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-5.png";
     
    344345                imageViewer("04 Close", test);
    345346
    346 //                Imgproc.threshold(test,test, 127, 255, Imgproc.THRESH_BINARY);
    347 //                imageViewer("05 Binarized", test);
     347                Imgproc.threshold(test,test, 127, 255, Imgproc.THRESH_BINARY);
     348                imageViewer("05 Binarized", test);
    348349
    349350                Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4));
     
    351352                imageViewer(" 06 Open", test);
    352353
    353 //                Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
    354 //                Imgproc.dilate(test, test, kernelDialateAgain);
    355 //                imageViewer("07 Dialate", test);
    356 
    357                 //FIGURE OUT FLOOD FILL!!
    358                 Imgproc.floodFill(test,test, new Point(1,1), new Scalar(2));
    359 
     354                Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
     355                Imgproc.dilate(test, test, kernelDialateAgain);
     356                imageViewer("07 Dialate", test);
    360357
    361358                Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,50));
    362359                Imgproc.morphologyEx(test,test,Imgproc.MORPH_CLOSE, kernelCloseAgain);
    363360                imageViewer(" 08 Close Again (Final)", test);
     361
     362                //FIGURE OUT FLOOD FILL!!
     363                //Imgproc.floodFill(test,test, new Point(1,1), new Scalar(2));
    364364
    365365            }
     
    857857//                Mat circleOutput = allContoursFound.clone();
    858858//                MatOfPoint2f[] contoursPoly  = new MatOfPoint2f[largeContours.size()];
     859//                Rect[] boundRect = new Rect[largeContours.size()];
    859860//                Point[] centers = new Point[largeContours.size()];
    860861//                float[][] radius = new float[largeContours.size()][1];
     
    864865//                    contoursPoly[i] = new MatOfPoint2f();
    865866//                    Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true);
     867//                    boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray()));
    866868//                    centers[i] = new Point();
    867869//                    Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]);
     
    870872//                //Draw circle for each large contour
    871873//                for (int i = 0; i < largeContours.size(); i++) {
     874//                    Imgproc.rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), color, 2);
    872875//                    Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1);
    873876//                }
     
    11571160                //Display Original
    11581161                imageViewer("original", original);
    1159                 Mat base = binarizedOriginal.clone();
    1160                 imageViewer("00 Inverse Binarized Original", base);
     1162                imageViewer("000 Inverse Binarized Original", binarizedOriginal);
    11611163
    11621164
    11631165                //************************************
    1164                 //1. Large object Remover
     1166                //1. Large Object Remover
    11651167                //************************************
    11661168                Mat srcLOR = binarizedOriginal.clone();
     
    11731175                imageViewer("001 De-noise", maskLOR);
    11741176
    1175                 //heal the large items
    1176                 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
     1177                //Heal the large items
     1178                Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25));
    11771179                Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR);
    11781180                imageViewer("002 heal objects in mask", maskLOR);
    11791181
    11801182                //IsolateLarge
    1181                 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,20));
    1182                 Imgproc.erode(maskLOR,maskLOR,isolateLargeLOR);
     1183                Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30));
     1184                Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR);
    11831185                imageViewer("003 Isolate large", maskLOR);
    11841186
     
    11871189                imageViewer("100 Large Items Removed", dstLOR);
    11881190
     1191                //                //CODE FROM PRESENTATION
     1192//                Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,1));
     1193//                Imgproc.erode(dstTOR,base,kernelErode);
     1194//                imageViewer("201 Erode", base);
     1195//
     1196//                Mat kernelDialate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(110,10));
     1197//                Imgproc.dilate(base, base, kernelDialate);
     1198//                imageViewer("202 Dialate", base);
     1199//
     1200//                Mat kernelErodeAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,20));
     1201//                Imgproc.erode(base,base,kernelErodeAgain);
     1202//                imageViewer(" 203 Erode Again", base);
     1203//
     1204//                Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(35,20));
     1205//                Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelClose);
     1206//                imageViewer("204 Close", base);
     1207//
     1208//                Imgproc.threshold(base,base, 127, 255, Imgproc.THRESH_BINARY);
     1209//                imageViewer("205 Binarized", base);
     1210//
     1211//                Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4));
     1212//                Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen);
     1213//                imageViewer("206 Open", base);
     1214//
     1215//                Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
     1216//                Imgproc.dilate(base, base, kernelDialateAgain);
     1217//                imageViewer("207 Dialate", base);
     1218//
     1219//                Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,50));
     1220//                Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain);
     1221//                imageViewer("208 Close Again (Final)", base);
     1222
    11891223                //***********************************
    1190                 //2. Text-sized Object Removal
     1224//                //3.1 Remove big outlines
     1225//                //***********************************
     1226//                Mat srcTOR = base.clone();
     1227//                Mat maskTOR = new Mat();
     1228//                Mat dstTOR = new Mat();
     1229//
     1230//                //Remove small objects in prep for masking (De-Noise)
     1231//                Mat removeSmallTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
     1232//                Imgproc.morphologyEx(srcTOR,maskTOR, Imgproc.MORPH_OPEN, removeSmallTOR);
     1233//                imageViewer("2101 Remove Small from mask", maskTOR);
     1234//
     1235//                //heal the large items
     1236//                Mat healTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
     1237//                Imgproc.morphologyEx(maskTOR,maskTOR, Imgproc.MORPH_CLOSE, healTOR);
     1238//                imageViewer("2102 heal objects in mask", maskTOR);
     1239//
     1240//                //Highlight black outline
     1241//                Mat highlightLargeTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
     1242//                Imgproc.erode(maskTOR,maskTOR,highlightLargeTOR);
     1243//                imageViewer("2103 highlight objects", maskTOR);
     1244//
     1245//                Core.bitwise_not(maskTOR, maskTOR);
     1246//                srcTOR.copyTo(dstTOR, maskTOR);
     1247//                imageViewer("2200 Black outline Removed", dstTOR);
     1248
     1249
     1250
     1251
     1252
     1253
     1254
     1255                //4. Classify like line clusters.
     1256                Mat base = binarizedOriginal.clone();
    11911257                //***********************************
    1192 
    1193                 Mat srcTOR = dstLOR.clone();
    1194                 Mat maskTOR = new Mat();
    1195                 Mat dstTOR = new Mat();
    1196 
    1197                 //Remove small objects in prep for masking (De-Noise)
    1198                 Mat removeSmallTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
    1199                 Imgproc.morphologyEx(srcTOR,maskTOR, Imgproc.MORPH_OPEN, removeSmallTOR);
    1200                 imageViewer("101 Remove Small from mask", maskTOR);
    1201 
    1202                 //heal the large items
    1203                 Mat healTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
    1204                 Imgproc.morphologyEx(maskTOR,maskTOR, Imgproc.MORPH_CLOSE, healTOR);
    1205                 imageViewer("102 heal objects in mask", maskTOR);
    1206 
    1207                 //Highlight black outline
    1208                 Mat highlightLargeTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
    1209                 Imgproc.erode(maskTOR,maskTOR,highlightLargeTOR);
    1210                 imageViewer("103 highlight objects", maskTOR);
    1211 
    1212                 Core.bitwise_not(maskTOR, maskTOR);
    1213                 srcTOR.copyTo(dstTOR, maskTOR);
    1214                 imageViewer("200 Black outline Removed", dstTOR);
    1215 
     1258                //3. Isolate straight lines
    12161259                //***********************************
    1217                 //3. Standard plan from presentation (TAKEN FROM CODE VERSION 5)
     1260                //Heal lines
     1261                Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(82,1));
     1262                Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL);
     1263                imageViewer("202 heal objects in mask", base);
     1264
     1265                //Make White Blobs
     1266
     1267                //NEED THIS??
     1268                Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,1));
     1269                Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen);
     1270                imageViewer("203 Open", base);
     1271                //NEED THIS?
     1272
     1273                Mat kernelDilateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
     1274                Imgproc.dilate(base, base, kernelDilateAgain);
     1275                imageViewer("204 Dilate", base);
     1276
     1277                Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12,50));
     1278                Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain);
     1279                imageViewer("205 Close Again (Final)", base);
     1280
    12181281                //***********************************
    1219                 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,2));
    1220                 Imgproc.erode(dstTOR,base,kernelErode);
    1221                 imageViewer("201 Erode plus pre", base);
    1222 
    1223                 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,2));
    1224                 Imgproc.dilate(base,base,kernelDilate);
    1225                 imageViewer("202 Dilate", base);
    1226 
    1227                 Mat kernelClosing = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,5));
    1228                 Imgproc.morphologyEx(base, base, Imgproc.MORPH_CLOSE, kernelClosing);
    1229                 imageViewer("203 Close", base);
    1230 
    1231                 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,2));
    1232                 Imgproc.erode(base,base,kernelErode02);
    1233                 imageViewer("204 Erode (Final)", base);
    1234 
    1235                 //4. Classify like line clusters.
     1282                //4. Find 'Clusters'
     1283                //   Need to find areas, using bounding boxes
     1284                //   Find how tall the bounding box is, if its taller than 'x' then classify as Sheet Music
     1285                //***********************************
     1286
     1287                //*****************************************************************
     1288                //4.1 Prep Rectangles on processed images
     1289                //*****************************************************************
     1290                ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
     1291                Mat hierarchy = new Mat();
     1292                Imgproc.findContours(base, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
     1293                //Draw contours and record areas
     1294                Mat allContoursFound = Mat.zeros(base.size(), CvType.CV_8UC3);
     1295                Mat rectOutput = allContoursFound.clone();
     1296                Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8
     1297                //Init arrays
     1298                MatOfPoint2f[] contoursPoly  = new MatOfPoint2f[contours.size()];
     1299                Rect[] boundRect = new Rect[contours.size()];
     1300
     1301                //Fill arrays
     1302                for (int i = 0; i < contours.size(); i++) {
     1303                    contoursPoly[i] = new MatOfPoint2f();
     1304                    Imgproc.approxPolyDP(new MatOfPoint2f(contours.get(i).toArray()), contoursPoly[i], 1, true);
     1305                    boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray()));
     1306                }
     1307                //Draw circle for each large contour
     1308                for (int i = 0; i < contours.size(); i++) {
     1309                    if(boundRect[i].height > 100){
     1310                        System.out.println("i:"+ i + " Height: " + boundRect[i].height);
     1311                        if(boundRect[i].width > 300){
     1312                            System.out.println("i:"+ i + " Width: " +  boundRect[i].width);
     1313                            Imgproc.rectangle(rectOutput, boundRect[i].tl(), boundRect[i].br(), new Scalar(255, 0, 0), 20);
     1314                        }
     1315                    }
     1316                }
     1317
     1318
     1319                imageViewer("4000 Rect found", rectOutput);
     1320
     1321
     1322
    12361323            }
    1237             //USE stuc element, to rule out large wide and long pieces of black and white.
    1238 
     1324            //ClassfierComparsion - Reset after david chat
     1325            if(CODE_VERSION == 91){
     1326                System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
     1327                Pair returnVariables = new Pair();
     1328                int areaCounter=0;
     1329                //Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
     1330                //Mat binarizedOriginal = original.clone();
     1331                //Imgproc.adaptiveThreshold(original, binarizedOriginal,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);
     1332                try{
     1333                    //************************************
     1334                    //1. Large Object Remover
     1335                    //************************************
     1336                    Mat srcLOR = binarizedOriginal.clone();
     1337                    Mat maskLOR = new Mat();
     1338                    Mat dstLOR = new Mat();
     1339
     1340                    //Remove small objects in prep for masking  (De-Noise)
     1341                    Mat removeSmallLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
     1342                    Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, removeSmallLOR);
     1343
     1344                    //Heal the large items
     1345                    Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25));
     1346                    Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR);
     1347
     1348                    //IsolateLarge
     1349                    Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30));
     1350                    Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR);
     1351
     1352                    Core.bitwise_not(maskLOR,maskLOR);
     1353                    srcLOR.copyTo(dstLOR, maskLOR);
     1354
     1355                    Mat base = binarizedOriginal.clone();
     1356                    //***********************************
     1357                    //3. Isolate straight lines
     1358                    //***********************************
     1359                    //Heal lines
     1360                    Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(82,1));
     1361                    Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL);
     1362
     1363                    //Make White Blobs
     1364                    Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,1));
     1365                    Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen);
     1366
     1367                    Mat kernelDilateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
     1368                    Imgproc.dilate(base, base, kernelDilateAgain);
     1369
     1370                    Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12,50));
     1371                    Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain);
     1372
     1373                    //***********************************
     1374                    //4. Find 'Clusters'
     1375                    //   Need to find areas, using bounding boxes
     1376                    //   Find how tall the bounding box is, if its taller than 'x' then classify as Sheet Music
     1377                    //***********************************
     1378
     1379                    //*****************************************************************
     1380                    //4.1 Prep Rectangles on processed images
     1381                    //*****************************************************************
     1382                    ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
     1383                    Mat hierarchy = new Mat();
     1384                    Imgproc.findContours(base, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
     1385                    //Draw contours and record areas
     1386                    Mat allContoursFound = Mat.zeros(base.size(), CvType.CV_8UC3);
     1387                    Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8
     1388                    //Init arrays
     1389                    MatOfPoint2f[] contoursPoly  = new MatOfPoint2f[contours.size()];
     1390                    Rect[] boundRect = new Rect[contours.size()];
     1391
     1392                    //Fill arrays
     1393                    for (int i = 0; i < contours.size(); i++) {
     1394                        contoursPoly[i] = new MatOfPoint2f();
     1395                        Imgproc.approxPolyDP(new MatOfPoint2f(contours.get(i).toArray()), contoursPoly[i], 1, true);
     1396                        boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray()));
     1397                    }
     1398                    //Draw circle for each large contour
     1399                    //MAKE THE COMPARING VALUES GLOBAL CONSTANTS
     1400                    for (int i = 0; i < contours.size(); i++) {
     1401                        if(boundRect[i].height > 100){
     1402                            if(boundRect[i].width > 300){
     1403                                areaCounter++;
     1404                            }
     1405                        }
     1406                    }
     1407
     1408                    //Classifier Calculation
     1409                    if(areaCounter >= THRESHOLD_AREA_COUNT){
     1410                        returnVariables.setBoolean(true);
     1411                        returnVariables.setInteger(areaCounter);
     1412                    }
     1413                }
     1414                catch(Exception e){
     1415                    System.err.println(e);
     1416                }
     1417                //return returnVariables;
     1418            }
    12391419
    12401420            //****************MORPHOLOGY****************************************************************************************
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/configClassifierComparison.properties

    r33447 r33458  
    1414#MORPHOLOGY
    1515THRESHOLD_AREA_SIZE         = 10000
    16 THRESHOLD_AREA_COUNT            = 10
     16THRESHOLD_AREA_COUNT            = 2
    1717
    1818
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java

    r33449 r33458  
    328328        return returnVariables;
    329329    }
    330     private static Pair Algorithm_MorphologyOLD(String filename){
     330    private static Pair Algorithm_MorphologyOLD2(String filename){
    331331
    332332        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
     
    386386        return returnVariables;
    387387    }
    388     private static Pair Algorithm_Morphology(String filename){
     388    private static Pair Algorithm_MorphologyOLD(String filename){
    389389
    390390        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
     
    573573                }
    574574            }
     575            //Classifier Calculation
     576            if(areaCounter >= THRESHOLD_AREA_COUNT){
     577                returnVariables.setBoolean(true);
     578                returnVariables.setInteger(areaCounter);
     579            }
     580        }
     581        catch(Exception e){
     582            System.err.println(e);
     583        }
     584        return returnVariables;
     585    }
     586    private static Pair Algorithm_Morphology(String filename){
     587        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
     588        Pair returnVariables = new Pair();
     589        int areaCounter=0;
     590        Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
     591        Mat binarizedOriginal = original.clone();
     592        Imgproc.adaptiveThreshold(original, binarizedOriginal,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);
     593        try{
     594            //************************************
     595            //1. Large Object Remover
     596            //************************************
     597            Mat srcLOR = binarizedOriginal.clone();
     598            Mat maskLOR = new Mat();
     599            Mat dstLOR = new Mat();
     600
     601            //Remove small objects in prep for masking  (De-Noise)
     602            Mat removeSmallLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
     603            Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, removeSmallLOR);
     604
     605            //Heal the large items
     606            Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25));
     607            Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR);
     608
     609            //IsolateLarge
     610            Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30));
     611            Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR);
     612
     613            Core.bitwise_not(maskLOR,maskLOR);
     614            srcLOR.copyTo(dstLOR, maskLOR);
     615
     616            Mat base = binarizedOriginal.clone();
     617            //***********************************
     618            //3. Isolate straight lines
     619            //***********************************
     620            //Heal lines
     621            Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(82,1));
     622            Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL);
     623
     624            //Make White Blobs
     625            Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,1));
     626            Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen);
     627
     628            Mat kernelDilateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
     629            Imgproc.dilate(base, base, kernelDilateAgain);
     630
     631            Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12,50));
     632            Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain);
     633
     634            //***********************************
     635            //4. Find 'Clusters'
     636            //   Need to find areas, using bounding boxes
     637            //   Find how tall the bounding box is, if its taller than 'x' then classify as Sheet Music
     638            //***********************************
     639
     640            //*****************************************************************
     641            //4.1 Prep Rectangles on processed images
     642            //*****************************************************************
     643            ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
     644            Mat hierarchy = new Mat();
     645            Imgproc.findContours(base, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
     646            //Draw contours and record areas
     647            Mat allContoursFound = Mat.zeros(base.size(), CvType.CV_8UC3);
     648            Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8
     649            //Init arrays
     650            MatOfPoint2f[] contoursPoly  = new MatOfPoint2f[contours.size()];
     651            Rect[] boundRect = new Rect[contours.size()];
     652
     653            //Fill arrays
     654            for (int i = 0; i < contours.size(); i++) {
     655                contoursPoly[i] = new MatOfPoint2f();
     656                Imgproc.approxPolyDP(new MatOfPoint2f(contours.get(i).toArray()), contoursPoly[i], 1, true);
     657                boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray()));
     658            }
     659            //Draw circle for each large contour
     660            //MAKE THE COMPARING VALUES GLOBAL CONSTANTS
     661            for (int i = 0; i < contours.size(); i++) {
     662                if(boundRect[i].height > 100){
     663                    if(boundRect[i].width > 300){
     664                        areaCounter++;
     665                    }
     666                }
     667            }
     668
    575669            //Classifier Calculation
    576670            if(areaCounter >= THRESHOLD_AREA_COUNT){
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh

    r33437 r33458  
    6969        #Runs javaImageClassifier on 10 images of each
    7070        for file in $source/SheetMusic/*.png; do
    71             if [ $i -lt 10 ] ; then
     71            if [ $i -lt 100 ] ; then
    7272                echo $file
    7373                echo $output
     
    7979        done
    8080        for file in $source/NotSheetMusic/*.png; do
    81             if [ $j -lt 10 ] ; then
     81            if [ $j -lt 100 ] ; then
    8282                echo $file
    8383                echo $output
Note: See TracChangeset for help on using the changeset viewer.