Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding read-image folder #10

Closed
wants to merge 1 commit into from

Conversation

verma-ananya
Copy link

@verma-ananya verma-ananya commented Mar 24, 2020

Following offline discussion with @krshrimali, we want to find a way to remove OpenCV dependency from the project. This will enable users to not require building OpenCV from source, which can create issues (see: https://github.com/opencv/opencv/issues?q=is%3Aopen+is%3Aissue+label%3A%22category%3A+build%2Finstall%22).

This PR attempts to start discussion on this topic. The first attempt is to compare using stb libraries for reading an image and resizing. Including the header files will be easier, and it will avoid the requirement to build the whole library (like OpenCV). This saves time, efforts but performance metric needs to be looked after.

Currently, this PR contains:

  1. Sample codes for reading an image file using the STB library (independent of image format). [Code is in both C and C++]
  2. Contains STB header files.

cc: @krshrimali

@krshrimali krshrimali linked an issue Mar 24, 2020 that may be closed by this pull request
@krshrimali krshrimali self-requested a review March 24, 2020 05:02
@krshrimali krshrimali added enhancement New feature or request open source Take up the task! But let us know... labels Mar 24, 2020
Copy link
Owner

@krshrimali krshrimali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work, @verma-ananya. I left some minor comments. It will be great if we can:

  • Add an example to resize an image using stb_image_resize library.
  • Add self explanatory comments in the code, to allow future changes.
  • Compare performance of OpenCV imread with stbi_load function.

Also, looking at the basic usage of stbi_load from https://github.com/nothings/stb/blob/master/stb_image.h#L124:

// Basic usage:
//    int x,y,n;
//    unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
//    // ... process data if not NULL ...
//    // ... x = width, y = height, n = # 8-bit components per pixel ...
//    // ... replace '0' with '1'..'4' to force that many components per pixel
//    // ... but 'n' will always be the number that it would have been if you said 0
//    stbi_image_free(data)

From what I understand, the fourth argument is number of channels in the input image, and fifth argument is the output number of channels that we want in our image (I may be wrong). If this is true, then does it also mean that the user needs to know the number of channels in their dataset while using stbi_load function?

@@ -0,0 +1,14 @@
#include <stdint.h>

#define STB_IMAGE_IMPLEMENTATION
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any note on why this definition is needed?

Comment on lines +1 to +14
##include <stdint.h>

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

int main() {
int width, height, bpp;

uint8_t* rgb_image = stbi_load("sky.jpg", &width, &height, &bpp, 3);

stbi_image_free(rgb_image);

return 0;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (image.cpp~) a possible duplicate of image.cpp file?

@krshrimali
Copy link
Owner

Closing this PR as this has been taken over by myself. I'll experiment using Selene! (https://github.com/kmhofmann/selene)

@krshrimali krshrimali closed this Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request open source Take up the task! But let us know...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove dependency of using OpenCV to read images
2 participants