Ejemplo n.º 1
0
	cv::Mat process(int newSize) {
		image = Thresholding(image).transform();
		
		// cut egdes:

		for (int i = 0; i < image.rows; i ++) {
			if (!processRow(i)) {
				break;
			}
		}

		for (int i = image.rows - 1; i >= 0; i --) {
			if (!processRow(i)) {
				break;
			}
		
		}

		for (int i = 0; i < image.cols; i ++) {
			if (!processCol(i)) {
				break;
			}
		}

		for (int i = image.cols - 1; i >= 0; i --) {
			if (!processCol(i)) {
				break;
			}
		}

		for (int i = 0; i < used.size(); i ++)
			for (int j = 0; j < used[i].size(); j ++)
				used[i][j] = 0;

		int L = 1;
		for (int i = 0; i < image.rows; i ++)
			for (int j = 0; j < image.cols; j ++) 
				if (image.at<uchar>(i, j) == BLACK && used[i][j] == 0) {
					dfs(i, j, L);
					L ++;
				}

		std::map<int,int> cnt;
		for (int i = 0; i < image.rows; i ++)
			for (int j = 0; j < image.cols; j ++) 
				if (used[i][j] != 0)
					cnt[used[i][j]] ++;

		int max_value = 0;
		int best_comp;
		for (std::map<int,int>::iterator it = cnt.begin(); it != cnt.end(); it ++)
			if (it->second > max_value) {
				max_value = it->second;
				best_comp = it->first;
			}
		
		for (int i = 0; i < image.rows; i ++)
			for (int j = 0; j < image.cols; j ++) 
				if (used[i][j] != best_comp) {
					image.at<uchar>(i,j) = WHITE;
				}

		int minRow = image.rows;
		int maxRow = -1;
		int minCol = image.cols;
		int maxCol = -1;
		
		for (int i = 0; i < image.rows; i ++)
			for (int j = 0; j < image.cols; j ++)
				if (image.at<uchar>(i,j) == BLACK) {
					minRow = std::min(minRow, i);
					maxRow = std::max(maxRow, i);
					minCol = std::min(minCol, j);
					maxCol = std::max(maxCol, j);
				}
		int X = minCol;
		int Y = minRow;
		int W = maxCol - minCol + 1;
		int H = maxRow - minRow + 1;
		int X0 = X - std::max(0, H - W) / 2;
		int Y0 = Y - std::max(0, W - H) / 2;
		try {
			image = Image::getSubMatrix(image, X0, Y0, std::max(W, H), std::max(W,H));
		} catch (...) {
		}
		cv::Mat newImage;
		cv::resize(image, newImage, cv::Size(newSize, newSize));
		newImage = Thresholding(newImage).transform();
		return newImage;
	}
Ejemplo n.º 2
0
static crosspoint_t ort_split_2(Sequence *seq0, Sequence *seq1, int i0, int j0, int i1, int j1,
						int type_s, int type_e, int score_s, int score_e,
						int *h0, int *h1, int *e0, int *e1, cell_t *r0, cell_t *r1, cell_t *c0, cell_t *c1) {

	if (DEBUG) printf("%d %d %d %d %d %d   %d %d\n", i0, j0, i1, j1, type_s, type_e, score_s, score_e);

	int seq0_len = i1-i0;
	int seq1_len = j1-j0;

	if (seq1_len >= H_MAX) {
		fprintf(stderr, "Partition size is too large (%d > %d). You need to store more special rows in stages 1-3.\n", seq1_len, H_MAX);
		exit(1);
	}

	int diff = 	(score_e + (type_e == TYPE_MATCH ? 0 : dna_gap_open)*0) - score_s;

	int imid = seq0_len/2;
	int imid0 = imid;
	int imid1 = seq0_len - imid; // (imid1 >= imid0) is always true

	int jmid = seq1_len/2;
	int jmid0 = jmid;
	int jmid1 = seq1_len - jmid; //  (jmid1 >= jmid0) is always true

	/* Forward */

	const char* s0 = seq0->getData(false)+(i0);
	const char* s1 = seq1->getData(false)+(j0);
	const char* s0r = seq0->getData(true)+(seq0->getInfo()->getSize()-i1);
	const char* s1r = seq1->getData(true)+(seq1->getInfo()->getSize()-j1);

//	for (int i=0; i<seq0_len; i++) {
//		printf("%d: %c%c\n", i, s0[i], s0r[i]);
//	}

	for (int i=0; i<imid0; i++) {
		c0[i].h = -(i+1)*dna_gap_ext - dna_gap_open*(type_s!=TYPE_GAP_2);
		c0[i].e = -INF;
	}
	for (int i=0; i<imid1; i++) {
		c1[i].h = -(i+1)*dna_gap_ext - dna_gap_open;//*(type_e!=TYPE_GAP_2);
		c1[i].e = -INF;
	}
	r0[0].h = r0[0].f = c0[imid0-1].h;
	r1[0].h = r1[0].f = c1[imid1-1].h;


	crosspoint_t cross;

	int d0 = (type_s!=TYPE_MATCH)?-INF:0;
	int d1 = (type_e!=TYPE_MATCH)?-INF:0;
	for (int j=0; j<seq1_len; j++) {
		int h0 = -(j+1)*dna_gap_ext - dna_gap_open*(type_s!=TYPE_GAP_1);
		cell_t rr0 = processCol(s0, s1[j], d0, h0, c0, imid0);
		d0 = h0;

		int h1 = -(j+1)*dna_gap_ext - dna_gap_open;//*(type_e!=TYPE_GAP_1);
		cell_t rr1 = processCol(s0r, s1r[j], d1, h1, c1, imid1);
		d1 = h1;

		if (j+1<=jmid1) {
			r0[j+1] = rr0;
			r1[j+1] = rr1;
		}
		if (DEBUG) printf("%d: %d %d  (%d %d) (%d %d)\n", j, rr0.h, rr1.h, imid0, imid1, jmid0, jmid1);

		if (j+1>=jmid1) {
			if (match(rr0, r1[seq1_len-(j+1)], diff, &cross)) {
				cross.j = j0+(j+1);
				cross.i = imid0+i0;
				cross.score += score_s;
				return cross;
			}
			if (match(r0[seq1_len-(j+1)], rr1, diff, &cross)) {
				cross.j = j0+(seq1_len-(j+1));
				cross.i = imid0+i0;
				cross.score += score_s;
				return cross;
			}
		}
	}
	if (DEBUG) printf("NOT FOUND %d\n", diff);
	fprintf(stderr, "NOT FOUND %d (%d %d %d %d - %d %d %d %d)\n", diff, type_s, i0, j0, score_s, type_e, i1, j1, score_e);
	exit(1);
}