Important changes to learn_model_traditional. Good results with vatican dataseT

parent 316484c8
......@@ -192,13 +192,16 @@ idx_t learn_model_traditional(binary_matrix& X,
E.copy_to(Eprev);
D.copy_to(Dprev);
A.copy_to(Aprev);
// cold restart!
A.clear();
X.copy_to(E);
coefficients_update(E,H,D,A,ma,me);
update_dictionary(E,H,D,A);
hdE = dist(E,Eprev);
hdD = dist(D,Dprev);
hdA = dist(A,Aprev);
reinitialize_unused(E,H,D,A);
} while (hdE > 0);
} while (hdE > 1e-3*E.get_len());
Eprev.destroy();
Aprev.destroy();
Dprev.destroy();
......
......@@ -21,6 +21,7 @@ const char* oname = "res/einstein_patches.pbm";
void parse_args(int argc, char **argv) {
if (argc < 4) {
std::cerr << "USAGE: " << argv[0] << " image.pbm patch_width stride patches.pbm" << std::endl;
std::cerr << "USAGE: " << argv[0] << " image.pbm wxxwy+sx+sy patches.pbm (imagemagick-like syntax, for non-square patches/grids" << std::endl;
exit(1);
}
iname = argv[1];
......
......@@ -7,13 +7,15 @@ from PIL import Image
WORD_DIR = u'/datos/data/vaticano/ya_binarizadas_y_segmentadas/data/ground_truth/word_images'
os.chdir(WORD_DIR)
#WORD_DIR = u'/datos/data/vaticano/ya_binarizadas_y_segmentadas/data/ground_truth/word_images'
WORD_DIR = u'vatican/word_images/'
EXT='pbm'
#os.chdir(WORD_DIR)
image_list = os.listdir(WORD_DIR)
maxh = 0
cumw = 0
margin = 50
margin = 25
means=[]
means2=[]
medians=[]
......@@ -21,7 +23,7 @@ modes=[]
heights=[]
for img in image_list:
img = img.strip()
I = np.asarray(Image.open(img)) == False
I = np.asarray(Image.open(WORD_DIR + img)) == False
height = I.shape[0]
cumw = cumw + I.shape[1] + margin
if height > maxh:
......@@ -56,7 +58,7 @@ center = maxh
i = 0
offset = 0
for img in image_list:
I = np.asarray(Image.open(img)) == False
I = np.asarray(Image.open(WORD_DIR + img)) == False
shift1 = center - int(means[i])
shift2 = center - int(modes[i])
shift3 = center - int(medians[i])
......@@ -83,5 +85,6 @@ bot = nz[-1]
top = nz[0]
Y = Y[top:bot,:]
#plt.savefig('Y.png')
#collage = Image.frombytes(mode='1',size=(Y.shape[1],Y.shape[0]),data=np.packbits(Y.astype(np.bool)))
collage = Image.frombytes(mode='L',size=(Y.shape[1],Y.shape[0]),data=255*Y.astype(np.uint8))
collage.save('../collage.pbm',compression='tiff_ccitt')
collage.save('./collage.pgm')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment