Example #1
0
    def _inccs(self, image, ccs=None):
        if ccs is None:
            ccs = set(image.cc_analysis())
        spikes = self._possible_text_areas(image=image, ccs=ccs)
        inccs = ccs_in_rspike(spikes, ccs)

        return inccs
Example #2
0
    def _inccs(self,image,ccs=None):
        if ccs is None:
            ccs = set(image.cc_analysis())
        spikes = self._possible_text_areas(image=image,
                                           ccs=ccs)
        inccs = ccs_in_rspike(spikes,ccs)

        return inccs
Example #3
0
    def _possible_text_areas(self, image=None, ccs=None):
        image = self._def_image(image)
        if ccs is None:
            ccs = image.cc_analysis()

        p, spikes = self._possible_text_areas_projection(image)

        for s in spikes[:]:
            cs = ccs_in_rspike([s], ccs)
            avgaspect = median([c.aspect_ratio()[0] for c in cs])

            if not (len(cs) > self._min_cc_count and between(
                    avgaspect, self._avg_cutoff[0], self._avg_cutoff[1])):
                self.l.debug("Avg aspect: %f, %d ccs", avgaspect, len(cs))
                spikes.remove(s)
        return spikes
Example #4
0
    def _possible_text_areas(self,
                             image=None,
                            ccs=None):
        image=self._def_image(image)
        if ccs is None:
            ccs = image.cc_analysis()

        p,spikes = self._possible_text_areas_projection(image)

        for s in spikes[:]:
            cs = ccs_in_rspike([s],ccs)
            avgaspect = median([ c.aspect_ratio()[0] for c in cs ])

            if not (len(cs) > self._min_cc_count and
                    between(avgaspect,self._avg_cutoff[0],self._avg_cutoff[1])):
                self.l.debug("Avg aspect: %f, %d ccs",avgaspect,len(cs))
                spikes.remove(s)
        return spikes
Example #5
0
    r =mi.with_row_projections(fac=fac)
    r = mi.draw_y_proj(p,image=r,color=RGBPixel(100,0,0),fac=fac)
    r.save_PNG("%s/%s-01-rowprojections.png"%(outputbase,basename))
    logging.debug("01-rowprojections.png")

    # draw in text areas based on these projections
    r = mi.to_rgb()
    width = mi._image.ncols-1
    for re in p.rspikes(width):
        r.draw_hollow_rect(re,RGBPixel(210,210,210))
    for re in sp:
        r.draw_hollow_rect(re,RGBPixel(150,150,150))
    ra = t._possible_text_areas()
    for re in ra:
        r.draw_hollow_rect(re,RGBPixel(255,0,0))
    firstccs = ccs_in_rspike(ra,mi.without_insidestaves_info().cc_analysis())

    for c in firstccs:
        r.highlight(c,RGBPixel(0,100,0))
    r.save_PNG("%s/%s-02-areas-and-ccs.png"%(outputbase,basename))
    logging.debug("02-areas-and-ccs.png")

    # Draw words
    r = mi.to_rgb()
    bsimg = mi.without_insidestaves_info()
    inccs = t._inccs(image=bsimg)
    for c in inccs:
        r.highlight(c,RGBPixel(0,200,0))

    words = wordlist(t._words(image=bsimg,ccs=inccs),inccs,t._min_wordlength)
    for c in words:
Example #6
0
    r = mi.with_row_projections(fac=fac)
    r = mi.draw_y_proj(p, image=r, color=RGBPixel(100, 0, 0), fac=fac)
    r.save_PNG("%s/%s-01-rowprojections.png" % (outputbase, basename))
    logging.debug("01-rowprojections.png")

    # draw in text areas based on these projections
    r = mi.to_rgb()
    width = mi._image.ncols - 1
    for re in p.rspikes(width):
        r.draw_hollow_rect(re, RGBPixel(210, 210, 210))
    for re in sp:
        r.draw_hollow_rect(re, RGBPixel(150, 150, 150))
    ra = t._possible_text_areas()
    for re in ra:
        r.draw_hollow_rect(re, RGBPixel(255, 0, 0))
    firstccs = ccs_in_rspike(ra, mi.without_insidestaves_info().cc_analysis())

    for c in firstccs:
        r.highlight(c, RGBPixel(0, 100, 0))
    r.save_PNG("%s/%s-02-areas-and-ccs.png" % (outputbase, basename))
    logging.debug("02-areas-and-ccs.png")

    # Draw words
    r = mi.to_rgb()
    bsimg = mi.without_insidestaves_info()
    inccs = t._inccs(image=bsimg)
    for c in inccs:
        r.highlight(c, RGBPixel(0, 200, 0))

    words = wordlist(t._words(image=bsimg, ccs=inccs), inccs,
                     t._min_wordlength)