In a pattern of single alphabet in an image I've written a small function which will start from any pixel and traverse all the contiguous pixels. In short in a matrix it will turn on all the contiguous pixels to true and rest will be zero.
This function has done it correctly. However with little change in input pattern it is behaving abnormally. I'm finding that this line onwards: //process left-up diagonally
is not getting called.
What could be the reason?
Also valgrind shows no memory corruption. The input jpg file size is 170x30 pixels maximum
System
Ubuntu-16
Makefile:
CFLAGS= -O2 -c -I$(INC_DIR) -fpermissive -std=c++11
CC=g++-5
%.o: %.cpp
$(CC) $(CFLAGS) -c $< -o $@
readpattern: readpattern.o
g++ -IPNG/include -o readpattern readpattern.o libcorona.a -lpng -ljpeg
Code
void do_start_extract_char(char **output, int x, int y, int width, int height) {
//if pixel location croses boundary then return
if (x < 0 || y < 0 || x > width - 1 || y > height - 1) {
return;
}
//if the same pixel has already been visited then just return
if (output[y][x]) {
return;
}
if (isUsefulPixel(x, y)) {
//store it
output[y][x] = 1;
} else {
return;
}
//process left
do_start_extract_char(output, x - 1, y, width, height);
//process down
do_start_extract_char(output, x, y + 1, width, height);
//process right
do_start_extract_char(output, x + 1, y, width, height);
//process up
do_start_extract_char(output, x, y - 1, width, height);
//process left-down diagonally
// /
// /
do_start_extract_char(output, x - 1, y + 1, width, height);
//process left-up diagonally
//
//
do_start_extract_char(output, x - 1, y - 1, width, height);
//process right-down diagonally
//
//
do_start_extract_char(output, x + 1, y + 1, width, height);
//process right-up diagonally
// /
// /
do_start_extract_char(output, x + 1, y - 1, width, height);
return;
}
See Question&Answers more detail:
os