示例#1
0
void main (int argc, char *argv[])
{
	SE p;
	IMAGE im;
	int k;

	if (argc < 4)
	{
	  printf ("BinDil <input> <Structuring element> <output>\n");
	  exit(1);
	}

/* Read the structuring element */
	k = get_se (argv[2], &p);
	if (!k)
	{
	  printf ("Bad structuring element, file name '%s'.\n", argv[2]);
	  exit (2);
	}
	printf ("BinDil: Perform a binary dilation on image '%s'.\n", 
		argv[1]);
	printf ("Structuring element is:\n");
	print_se (p);

/* Read the input image */
	if (read_pbm (argv[1], &im) == 0) exit(3);

/* Perform the dilation */
	bin_dilate (im, p);

/* Write the result to the specified file */
	write_pbm (argv[3], im);
}
示例#2
0
bool test_spiral_8()
{
    /* State:
     *
     * |LSB       MSB|
     * 1 1 1 1 1 1 1 1
     * 1 0 0 0 0 0 0 1
     * 1 1 1 1 1 1 0 1
     * 1 0 0 0 0 1 0 1
     * 1 0 1 1 0 1 0 1
     * 1 0 1 0 0 1 0 1
     * 1 0 1 1 1 1 0 1
     * 1 0 0 0 0 0 0 1
     * 1 1 1 1 1 1 1 1
     */
    
    /* Easier to put into hex
     *LSB                                       MSB
     * 1111 1111 1000 0001 1111 1101 1000 0101
     * 1011 0101 1010 0101 1011 1101 1000 0001
     * 1111 1111
     */

    uint32_t * state;

    const uint32_t expected_state[] = {
        0xa1bf81ff,
        0x81bda5ad,
        0xff
    };

    read_pbm("tests/pbm/spiral_8_start.pbm", &state, &state_width, &state_height, NULL);

    ints_per_state = ((state_width * state_height) / 32) + ((state_width * state_height)%32) > 0 ? 1 : 0;
    state_size = ints_per_state * 4;

    if (state_width != 8 && state_height != 9)
    {
        printf("width: %u, expected_width: %u\n", state_width, 8);
        printf("height: %u, expected_height: %u\n", state_height, 9);

        return false;
    }
    else if (!states_equal(state, expected_state))
    {
        puts("state read:");
        print_state(state);

        puts("state expected:");
        print_state(expected_state);

        return false;
    }

    return true;
}
示例#3
0
Matrix<Color> read_img(std::string filename)
{
    std::size_t n = filename.size();
    std::string extension3 = filename.substr(n-3, n);
    std::string extension4 = filename.substr(n-4, n);
    if(!extension3.compare("bmp"))
    {
        return read_bmp(filename);
    }
    else if(!extension3.compare("gif"))
    {
        return read_gif(filename);
    }
    else if(!extension3.compare("ico"))
    {
        return read_ico(filename);
    }
    /*else if(!extension3.compare("jpg"))
    {
        return read_jpeg(filename);
    }*/
    else if(!extension3.compare("pcx"))
    {
        return read_pcx(filename);
    }
    else if(!extension3.compare("png"))
    {
        return read_png(filename);
    }
    else if(!extension3.compare("pbm"))
    {
        return bw2colorimage(read_pbm(filename));
    }
    else if(!extension3.compare("pgm"))
    {
        return gray2colorimage(read_pgm(filename));
    }
    else if(!extension3.compare("ppm"))
    {
        return read_ppm(filename);
    }
    else if(!extension3.compare("tga"))
    {
        return read_tga(filename);
    }
    else if(!extension4.compare("tiff"))
    {
        return read_tiff(filename);
    }
    else
    {
        return Matrix<Color>();
    }
}
示例#4
0
bool test_61c()
{
    /* State:
     *
     * |LSB                         MSB|
     * 1 1 1 0 1 1 1 0 1 0 0 0 1 0 1 1 1
     * 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0
     * 1 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 0
     * 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0
     * 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1
     */
/* This is to make it easier to put into hex
1110 1110 1000 1011 1100 0100 0100 0101
0010 0011 1011 1010 1001 0000 0101 0101
0100 1110 1110 1110 1011 1
 */
    uint32_t * state;

    const uint32_t expected_state[] = {
        0xa223d177,
        0xaa095dc4,
        0x1d7772
    };

    read_pbm("tests/pbm/61c_end.pbm", &state, &state_width, &state_height, NULL);

    ints_per_state = ((state_width * state_height) / 32) + ((state_width * state_height)%32) > 0 ? 1 : 0;
    state_size = ints_per_state * 4;

    if (state_width != 17 && state_height != 5)
    {
        printf("width: %u, expected_width: %u\n", state_width, 17);
        printf("height: %u, expected_height: %u\n", state_height, 5);

        return false;
    }
    else if (!states_equal(state, expected_state))
    {
        puts("state read:");
        print_state(state);

        puts("state expected:");
        print_state(expected_state);

        return false;
    }

    return true;
}
示例#5
0
bool test_simple()
{
    /* State:
     *
     * |LSB MSB|
     * 1 0 0 1 0
     * 0 0 0 0 1
     * 0 1 0 0 0
     */

    /* State:
     * Easier to put into hex
     * |LSB            MSB|
     *  1001 0000 0101 000
     */
    
    uint32_t * state;

    const uint32_t expected_state[] = {
        0xa09
    };

    read_pbm("tests/pbm/simple_start.pbm", &state, &state_width, &state_height, NULL);

    ints_per_state = ((state_width * state_height) / 32) + ((state_width * state_height)%32) > 0 ? 1 : 0;
    state_size = ints_per_state * 4;

    if (state_width != 5 && state_height != 3)
    {
        printf("width: %u, expected_width: %u\n", state_width, 8);
        printf("height: %u, expected_height: %u\n", state_height, 9);
        
        return false;
    }
    if (!states_equal(state, expected_state))
    {
        puts("state read:");
        print_state(state);

        puts("state expected:");
        print_state(expected_state);

        return false;
    }

    return true;
}
示例#6
0
int ConnectedComponentLabeling(char *fn, char *option)
{
	int height, width, cx, cy, tracingdirection, ConnectedComponentsCount = 0, labelindex = 0;
	char buf[256];
	
	if(read_pbm(fn, &width, &height, option) != 1)
	{
		return -1;
	}
	printf("%d,%d", height,width);
	for(cy = 1; cy < height - 1; cy++)
	{
		for(cx = 1, labelindex = 0; cx < width - 1; cx++)
		{
			if(bitmap[cy][cx] == 1)// black pixel
			{
				if(labelindex != 0)// use pre-pixel label
				{
					labelmap[cy][cx] = labelindex;
				}
				else
				{
					labelindex = labelmap[cy][cx];

					if(labelindex == 0)
					{
						labelindex = ++ConnectedComponentsCount;
						tracingdirection = 0;
						ContourTracing(cy, cx, labelindex, tracingdirection, option);// external contour
						labelmap[cy][cx] = labelindex;
					}
				}
			}
			else if(labelindex != 0)// white pixel & pre-pixel has been labeled
			{
				if(labelmap[cy][cx] == 0)
				{
					tracingdirection = 1;
					ContourTracing(cy, cx - 1, labelindex, tracingdirection, option);// internal contour
				}

				labelindex = 0;
			}
		}
	}

	cx = strlen(fn);
	memcpy(buf, fn, cx - 4);
	buf[cx - 4] = '\0';
	strcat(buf, "_");
	strcat(buf, option);
	write_rlt(buf, ConnectedComponentsCount, width, height, option);
	fprintf(stderr, "CC# %d.\n", ConnectedComponentsCount);

	for(cy = 0; cy < height; cy++)
	{
		free(bitmap[cy]);
		free(labelmap[cy]);

		if(option == "1")
		{
			free(contourmap[cy]);
		}
	}

	free(bitmap);
	free(labelmap);

	if(option == "1")
	{
		free(contourmap);
	}

	return 1;
}