Skip to content

Instantly share code, notes, and snippets.

@liuliu
Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save liuliu/8906523 to your computer and use it in GitHub Desktop.
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