Create a gist now

Instantly share code, notes, and snippets.

@liuliu /gist:8906523
Last active Aug 29, 2015

Embed
What would you like to do?
resize image to 257x257
ccv_size_t size = ccv_size(257, 257);
for (i = 0; i < categorizeds->rnum; i++)
{
ccv_categorized_t* categorized = (ccv_categorized_t*)ccv_array_get(categorizeds, i);
ccv_dense_matrix_t* image = 0;
ccv_read(categorized->file.filename, &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
if (image)
{
ccv_dense_matrix_t* norm = 0;
if (image->rows > size.height && image->cols > size.width)
ccv_resample(image, &norm, 0, ccv_max(size.height, (int)(image->rows * (float)size.height / image->cols + 0.5)), ccv_max(size.width, (int)(image->cols * (float)size.width / image->rows + 0.5)), CCV_INTER_AREA);
else if (image->rows < size.height || image->cols < size.width)
ccv_resample(image, &norm, 0, ccv_max(size.height, (int)(image->rows * (float)size.height / image->cols + 0.5)), ccv_max(size.width, (int)(image->cols * (float)size.width / image->rows + 0.5)), CCV_INTER_CUBIC);
else
norm = image;
if (norm != image)
ccv_matrix_free(image);
char filename[1024];
snprintf(filename, 1024, "%s.resize.png", categorized->file.filename);
ccv_write(norm, filename, 0, CCV_IO_PNG_FILE, 0);
ccv_dense_matrix_t* patch = 0;
int x = (norm->cols - size.width) / 2;
int y = (norm->rows - size.height) / 2;
ccv_slice(norm, (ccv_matrix_t**)&patch, CCV_64F, y, x, size.width, size.height);
ccv_matrix_free(norm);
ccv_matrix_free(patch);
FLUSH("done %s, %d / %d", filename, i + 1, categorizeds->rnum);
} else {
printf("\ncannot handle %s\n", categorized->file.filename);
}
}
printf("\n");
for (i = 0; i < tests->rnum; i++)
{
ccv_categorized_t* categorized = (ccv_categorized_t*)ccv_array_get(tests, i);
ccv_dense_matrix_t* image = 0;
ccv_read(categorized->file.filename, &image, CCV_IO_ANY_FILE | CCV_IO_RGB_COLOR);
if (image)
{
ccv_dense_matrix_t* norm = 0;
if (image->rows > size.height && image->cols > size.width)
ccv_resample(image, &norm, 0, ccv_max(size.height, (int)(image->rows * (float)size.height / image->cols + 0.5)), ccv_max(size.width, (int)(image->cols * (float)size.width / image->rows + 0.5)), CCV_INTER_AREA);
else if (image->rows < size.height || image->cols < size.width)
ccv_resample(image, &norm, 0, ccv_max(size.height, (int)(image->rows * (float)size.height / image->cols + 0.5)), ccv_max(size.width, (int)(image->cols * (float)size.width / image->rows + 0.5)), CCV_INTER_CUBIC);
else
norm = image;
if (norm != image)
ccv_matrix_free(image);
char filename[1024];
snprintf(filename, 1024, "%s.resize.png", categorized->file.filename);
ccv_write(norm, filename, 0, CCV_IO_PNG_FILE, 0);
ccv_matrix_free(norm);
FLUSH("done %s, %d / %d", filename, i + 1, tests->rnum);
} else {
printf("\ncannot handle %s\n", categorized->file.filename);
}
}
printf("\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment