Example #1
0
def image_calc(img):

    try:

        #img = cv2.imdecode(str2
        #img = cv2.imread(str2)
        correct_fea = Gist_feat_last.singleImage2(img)
        feat = HOG_feat2.hog_call(img)
        #print 'hog',feat.shape
        #print 'correct shape',correct_fea.shape
        Label_classify2(feat,'batman')
        Label_classify(correct_fea,'batman')
        print 'list',list1
        print '2nd list',list2
	
        for file12 in files_name:
            list3[file12] = []
            names = list1[file12]
            names2 = list2[file12]
            l1 = list(set(names).intersection(names2))
            l1 = remove_num(l1)
            l1=list(set(l1))
            list3[file12] = l1
            print 'last',list3
            return list3

    except Exception,e:
        return 'Image not found' 
Example #2
0
def single_affine(img,name):
    #img = cv2.imread(path)
    #modify_database(name)
    img = imresize(img, (47*2, 55*2), interp = 'bicubic')

    cv2.imwrite("/root/ideaswirw/imageprocessing/DataBase/1.png",img)
    #print 'image is',img
    #print img.shape
    histogram.add_hist(img, name)

    gist_feat = Gist_feat_last.singleImage2(img)
    hog_feat = HOG_feat2.hog_call(img)
    gist_feat = np.concatenate((gist_feat,[1]))
    hog_feat = np.concatenate((hog_feat,[1]))
    with open(feat_gist+name+'.csv', 'a') as myfile:
        wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
        wr.writerow(gist_feat)
    with open(feat_hog+name+'.csv', 'a') as myfile:
        wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
        wr.writerow(hog_feat)
    '''
    add_feature_to_database(name,gist_feat,"Gabor")
    add_feature_to_database(name,hog_feat,"HOG")
    '''
    ret = generate_affine(img,name)
    
    return ret
Example #3
0
def image_calc(img):

    img = imresize(img, (47 * 2, 55 * 2), interp='bicubic')
    correct_fea = Gist_feat_last.singleImage2(img)
    feat = HOG_feat2.hog_call(img)

    orig_hog = Label_classify2(feat, 'batman')
    orig_gist = Label_classify(correct_fea, 'batman')

    orig_res = gen_res(orig_hog, orig_gist)

    af_img = afine_search.affine_transform(img)

    af_gist = Gist_feat_last.singleImage2(af_img)
    af_hog = HOG_feat2.hog_call(af_img)
    aff_hog = Label_classify2(feat, 'batman')
    aff_gist = Label_classify(correct_fea, 'batman')
    af_res = gen_res(aff_hog, aff_gist)

    final_res = list(set(orig_res).intersection(af_res))

    #final_response = histogram.search_hist(final_res, img)
    print final_res
    print orig_res
    print af_res
    print orig_hog
    print orig_gist
    print aff_hog
    print aff_gist
    new_hog, hog_weig = make_final_hog(aff_hog, orig_hog)
    new_gist, gist_weig = make_final_hog(aff_gist, orig_gist)
    if hog_weig > gist_weig:
        return new_hog
    elif hog_weig < gist_weig:
        if gist_weig > 1:
            return new_gist
        else:
            return []
    elif hog_weig == gist_weig:
        temp = []
        for x in new_hog:
            temp.append(x)
        for x in new_gist:
            temp.append(x)
        return temp
Example #4
0
def image_calc(img):

    img = imresize(img, (47*2, 55*2), interp = 'bicubic')
    correct_fea = Gist_feat_last.singleImage2(img)
    feat = HOG_feat2.hog_call(img)

    orig_hog = Label_classify2(feat,'batman')
    orig_gist = Label_classify(correct_fea,'batman')

    orig_res = gen_res(orig_hog, orig_gist)

    af_img = afine_search.affine_transform(img)

    af_gist = Gist_feat_last.singleImage2(af_img)
    af_hog = HOG_feat2.hog_call(af_img)
    aff_hog = Label_classify2(feat,'batman')
    aff_gist = Label_classify(correct_fea,'batman')
    af_res = gen_res(aff_hog, aff_gist)

    final_res = list(set(orig_res).intersection(af_res))

    final_response = histogram.search_hist(final_res, img)
    return final_response
Example #5
0
def single_affine(img, name):
    #img = cv2.imread(path)
    #modify_database(name)
    gist_feat = Gist_feat_last.singleImage2(img)
    hog_feat = HOG_feat2.hog_call(img)
    gist_feat = np.concatenate((gist_feat, [1]))
    hog_feat = np.concatenate((hog_feat, [1]))
    with open(feat_gist + name + '.csv', 'a') as myfile:
        wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
        wr.writerow(gist_feat)
    with open(feat_hog + name + '.csv', 'a') as myfile:
        wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
        wr.writerow(hog_feat)
    '''
    add_feature_to_database(name,gist_feat,"Gabor")
    add_feature_to_database(name,hog_feat,"HOG")
    '''
    ret = generate_affine(img, name)

    return ret
Example #6
0
def generate_affine(img, name):
    #for i in range(10):
    for i in range(30):

        #padd the image
        img1 = padd(img)
        #cv2.imshow('after concatat',img1)
        #cv2.waitKey()
        gamma_1 = random_1()
        gamma_main = random.randrange(1, 3, 1)
        gamma_last = gamma_main + gamma_1
        noise_addition = adjust_gamma(
            img1, gamma=gamma_last)  #change the gammmaa of the image randomly
        noise_ad2 = sp.noise_addition(
            noise_addition)  #add the salt and peppr noise to the image
        pts1 = np.float32([[50, 50], [200, 50], [50, 200]])
        (h, w) = img1.shape[:2]
        rows2, cols2, ch2 = img1.shape  #ch=3 rows = hieght and col is width

        #creating the rotation matrix
        x = random.randrange(-3, 3, 1)

        y = random.random()
        z = x + y
        x = math.radians(z)

        sin = math.sin(x)
        cos = math.cos(x)
        rotation = [[cos, sin], [-sin, cos]]  #2x2 rotation matrix
        #shear matrices

        shear_fact_x = -0.05 + random_2()  #take random values for both x and y
        shear_fact_y = -0.05 + random_2()
        shear_x = [[1, shear_fact_x], [0, 1]]
        shear_y = [[1, 0], [shear_fact_y, 1]]
        shear_new = np.array(shear_x, dtype=np.float32)
        rotation_new = np.array(rotation, dtype=np.float32)

        #multiplying 2D matrices
        afine_t = np.dot(shear_new, rotation_new)
        shear_new = np.array(shear_y, dtype=np.float32)
        afine_t2 = np.dot(afine_t, shear_new)
        #afine_t = shear_new
        pts2 = np.dot(pts1, afine_t2)  #new points use for warping the image
        #print pts2
        #cv2.imshow('Affine_2',img)
        #cv2.waitKey()
        s11, s12, s13 = noise_ad2.shape
        for r in range(s11):
            for c in range(s12):
                if np.all(noise_ad2[r, c, :] == 0):

                    noise_ad2[r, c, 0] = noise_ad2[r, c, 0] + 1
                    noise_ad2[r, c, 1] = noise_ad2[r, c, 1] + 1
                    noise_ad2[r, c, 2] = noise_ad2[r, c, 2] + 1

        M = cv2.getAffineTransform(pts1, pts2)
        dst = cv2.warpAffine(noise_ad2, M, (cols2, rows2))  #get afine of image
        #cv2.imshow('imshow',dst)
        #cv2.imshow('Affine_3',dst)
        #cv2.waitKey()
        s1, s2, s3 = dst.shape
        #removing the extra black areas from the images so that only logos is visible.

        count = 0
        count2 = 0
        for r in range(s1):
            num = count_rows(dst[r, :, :])
            #print '*******NUM*******', num
            if num >= 30:
                count = count + 1
                #break
            else:
                #count = count+1
                break
        for c in range(s2):
            num2 = count_rows(dst[:, c, :])
            #print '*******NUM*******1\t', num2
            if (num2 >= 30):
                count2 = count2 + 1
                #break
            else:
                #count2 = count2+1
                break

        r1 = s1 - 1
        while (r1 >= 0):
            num3 = count_rows(dst[r1, :, :])
            #print '*******NUM*******2\t', num3
            if (num3 >= 30):
                #break
                r1 = r1 - 1
            else:
                #r1=r1-1
                break
        c1 = s2 - 1
        while (c1 >= 0):
            num4 = count_rows(dst[:, c1, :])
            #print '*******NUM*******3\t', num4
            if (num4 >= 30):
                #break
                c1 = c1 - 1
            else:
                #c1 = c1-1
                break
    # print 'first and  last also col1 and col2',r1,count,count2,c1

        dst2 = dst[count:r1, count2:c1]
        #major change
        or_image_x, or_image_y, or_image_z = img.shape
        #dst2 = dst
        s1, s2, s3 = dst2.shape
        t2 = (-or_image_y + s2) / 2
        t1 = (-or_image_x + s1) / 2
        #print '***t2,t2***', t1, t2

        count = r1 = c1 = count2 = 0

        #print '*******s1*******', s1, s2, s3
        if s1 > 100 and s2 > 100:
            dst2 = dst2[t1:s1 - t1, t2:s2 - t2]
            #cv2.imshow('Affine',dst2)
            #cv2.waitKey()
        else:
            #print '******AFFINE FAILED********'
            dst2 = img  #comping original image to dst
        #add the gist and hog feature of the image
        if s2 != 0 and s1 != 0:

            #        cv2.imshow('noise',dst2)
            #dst2 remove black.
            gist_feat = Gist_feat_last.singleImage2(dst2)
            hog_feat = HOG_feat2.hog_call(dst2)
            gist_feat = np.concatenate((gist_feat, [1]))
            hog_feat = np.concatenate((hog_feat, [1]))
            '''add_feature_to_database(name,gist_feat,"Gabor")
            add_feature_to_database(name,hog_feat,"HOG")'''

            with open(feat_gist + name + '.csv', 'a') as myfile:
                wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
                wr.writerow(gist_feat)
            with open(feat_hog + name + '.csv', 'a') as myfile:
                wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
                wr.writerow(hog_feat)

    return i
Example #7
0
def image_calc(img):

    try:

        #img = cv2.imdecode(str2
        #img = cv2.imread(str2)
        global list1
        global list2
        global files_name
        print 'feature here'
        correct_fea = Gist_feat_last.singleImage2(img)
        feat = HOG_feat2.hog_call(img)
        #print 'hog',feat.shape
        #print 'correct shape',correct_fea.shape
        print 'shapes'
        Label_classify2(feat, 'batman')
        Label_classify(correct_fea, 'batman')
        print 'list', list1
        print '2nd list', list2
        temp_list1 = []
        temp_list2 = []
        last_list = []
        ret_list1 = []
        ret_list2 = []
        ret_val = []
        print list1
        print list2
        list11 = list1.values()
        list12 = list2.values()

        for file12 in files_name:
            print 'in loop'
            names = list1[file12]
            names2 = list2[file12]
            print 'got  the list'
            list1_new = remove_num(names)
            list2_new = remove_num(names2)
            list1_set = set(list1_new)
            list2_set = set(list2_new)
            print 'occ table made'
            o1 = make_occurence_table(list1_set, list1_new)
            o2 = make_occurence_table(list2_set, list2_new)
            for labels in o2:
                if o1.has_key(labels):
                    ret_temp = o2[labels]
                    o2[labels] = ret_temp + o1[labels]
            max_mata = o2.values()
            val_ans = max(max_mata)
            for ans_ret in o2:
                if o2[ans_ret] == val_ans:
                    ret_val.append(ans_ret)
            temp_list2 = ret_key(o1, 2)
            temp_list1 = ret_key(o2, 2)

            last_list = list(set(temp_list1).intersection(set(temp_list2)))

        return list(set(ret_val))
        #for file12 in files_name:
        #list3[file12] = []
        #names = list1[file12]
        #names_new = remove_num(names)
        #names2 = list2[file12]
        #names2_new = remove_num(names2)
        #l1 = list(set(names_new).intersection(names2_new))
        #l1 = remove_num(l1)
        #l1=list(set(l1))
        #list3[file12] = l1
        #print 'last',list3
        #return list3

    except Exception, e:
        print 'Exception', e
        return list()
Example #8
0
def image_calc(img):
	
    '''s1 = str2
    s4 = s1.split('path')[1]
    s4 = s4[1:]
    s4 = s4.split('>')[0]
    str2 = s4.replace('//', '\\')
    print 'image s',str2'''
    try:

        #img = cv2.imdecode(str2
        #img = cv2.imread(str2)
        global list1
        global list2
        global files_name
        correct_fea = Gist_feat_last.singleImage2(img)
        feat = HOG_feat2.hog_call(img)
        annoyfeature = np.concatenate((correct_fea,feat))
        #print 'hog',feat.shape
        print 'Feature extracted'
        Label_classify2(feat,'batman')
        Label_classify(correct_fea,'batman')
        #print 'list',list1
        #print '2nd list',list2
        temp_list1 = []
        temp_list2 = []
        last_list=[]
        ret_list1 = []
        ret_list2 = []
        print list1
        print list2
        for file12 in files_name:
            print 'in loop'
            names = list1[file12]
            names2 = list2[file12]
            print 'got  the list'
            list1 = remove_num(names)
            list2 = remove_num(names2)
            list1_set = set(list1)
            list2_set = set(list2)
            print 'occ table made'
            o1 = make_occurence_table(list1_set,list1)
            o2 = make_occurence_table(list2_set,list2)
            temp_list2 = ret_key(o1,2)
            temp_list1 = ret_key(o2,2)

            last_list = list(set(list1).intersection(set(list2)))
        #lab1,distances = final_labels(temp_list1,'Hog')
        #lab2,distances2 = final_labels(temp_list2,'Gist')
        #hog_min = distances.min()
        #gist_min = distances2.min()
        #print 'lst',last_list,annoyfeature
        print 'b4 annoy'
        lab1,distances = combine_labels(last_list,annoyfeature)
        print "after annoy"
        mindist = distances.min()
        for i in lab1:
            if lab1[i] == hog_min:
                ret_list2.append(i)
        #for i in lab2:
        #    if lab2[i] == gist_min:
        #        ret_list1.append(i)
        #print 'last',list3
        #last_list = list(set(ret_list1).intersection(ret_list2))
        return ret_list2

    except Exception,e:
        return 'Image not found',e