public GrayU8 loadBinaryImage(int id) { try { File directory = owner.getApplicationContext().getDir(DIRECTORY_NAME,Context.MODE_PRIVATE); BufferedReader input = new BufferedReader(new FileReader(new File(directory,id+""))); String words[] = input.readLine().split(" "); int width = Integer.parseInt(words[0]); int height = Integer.parseInt(words[1]); GrayU8 image = new GrayU8(width,height); for (int y = 0; y < image.height; y++) { String line = input.readLine(); if( line.length() != width ) return null; for (int x = 0; x < image.width; x++) { int value = line.charAt(x); image.unsafe_set(x,y,value); } } return image; } catch (IOException e) { throw new RuntimeException(e); } }
protected void performThresholding(float threshLow, float threshHigh, GrayU8 output) { if( hysteresisPts != null ) { hysteresisPts.process(suppressed,direction,threshLow,threshHigh); // if there is an output image write the contour to it if( output != null ) { ImageMiscOps.fill(output, 0); for( EdgeContour e : hysteresisPts.getContours() ) { for( EdgeSegment s : e.segments) for( Point2D_I32 p : s.points ) output.unsafe_set(p.x,p.y,1); } } } else { hysteresisMark.process(suppressed,direction,threshLow,threshHigh,output); } }
/** * Checks to see if the given coordinate is above the lower threshold. If it is the point will be * added to the current segment or be the start of a new segment. * * @param match Has a match to the current segment already been found? * @return true if a match was found at this point */ private boolean check( int x , int y , boolean match ) { if( intensity.isInBounds(x,y) ) { int index = intensity.getIndex(x,y); if( intensity.data[index] >= lower ) { intensity.data[index] = MARK_TRAVERSED; output.unsafe_set(x,y,1); if( match ) { open.grow().set(x, y); } else { active.set(x,y); } return true; } } return false; } }
output.unsafe_set(fx, fy, 1); active.set(fx, fy); match = true; output.unsafe_set(bx,by,1); if( match ) { open.grow().set(bx,by);