symisc / sod

An Embedded Computer Vision & Machine Learning Library (CPU Optimized & IoT Capable)
https://sod.pixlab.io
Other
1.75k stars 213 forks source link

Single channel/Gray scale depth not working #14

Closed TrevorHeyl closed 5 years ago

TrevorHeyl commented 5 years ago

Hi,

I am trying out some processing with grayscale and black and white images, I find some problems with channel depth in some functions.

I am using Windows 7 and the GNU compiler with Codeblocks as IDE.

When using _sod_img_blob_save_asbmp() with channels set to 1, the output still contains 3 channels. Below is some code I used to test this.

`
sod_img imgIn = sod_img_load_from_file(zInput,SOD_IMG_GRAYSCALE); //

/* Perform canny edge detection. */
sod_img imgOut = sod_canny_edge_image(imgIn, 0 );

    /* Finally save our processed image to the specified path */
/* first make it a blob so we can use bmp saving)
unsigned char *zPng = sod_image_to_blob(imgOut);
sod_img_blob_save_as_bmp(zOut, zPng, 240, 240, 1  );

`

symisc commented 5 years ago

Could you share the full code you used to read the image until the save process and a link to the image in question? Thanks.

TrevorHeyl commented 5 years ago

As requested, see here for a project : https://github.com/TrevorHeyl/SOD_TestGrayScaleBMP and here for the images : (same proejct) https://github.com/TrevorHeyl/SOD_TestGrayScaleBMP/tree/master/SOD_test/res The input images are image01...bmp and the output images out...bmp

I have used Codeblocks 17.2 for this project

As you can see the output files are always 172854 bytes in size even if I specify 1 single channel. Notice the one input file of 16bit is 115338K, this corresponds with an image of 240x240x16 bit approx. So I expect the output file to be about 60K for 8 bit grayscale.

Thanks

symisc commented 5 years ago

All right,

you should probably load the image normally (i.e. sod_img_load_from_file(zInput, SOD_IMG_COLOR)) without forcing on grayscale colorspace conversion like you did and apply the Grayscale conversion later via sod_grayscale_image().

TrevorHeyl commented 5 years ago

Thanks for the answer.