Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.
This repository was archived by the owner on May 24, 2018. It is now read-only.

Does CXXNET support grey scale images? #200

Description

@haowu3

Hi,

I used img iterator (image list) for grey images, but it gives a shape mistach error. Then I traced into the program and found LoadImage function used in ImageIterator class loads images as RGB images. Its output will always have 3 channels.

Does any data iterator supports grey scale images?
If not, will implementing such an iterator work well? or there is some other part of the project also assumes all images are RGB therefore that will not work?

Activity

  1. winstywang commented on Jul 17, 2015

    @winstywang
    Contributor

    A fast workaround is to convert the grayscale image into color image... If you want to use grayscale image, you can implement a new data iterator for it. Other part does not assume this.

  2. juliandewit commented on Jul 17, 2015

    @juliandewit

    I made a quick and dirty version of the grayscale img iterator.
    It worked.. no rgb assumptions further in the pipeline..

    ...
    inline static void LoadImage(mshadow::TensorContainer<cpu,3> &img, DataInst &out,const char fname, int grayscale) {

    cv::Mat res = cv::imread(fname);
    utils::Assert(res.data != NULL, "LoadImage: Reading image %s failed.\n", fname);
    //utils::Assert(img.size(0) == 1, "Grayscale requires one channel.\n");
    int channel_count = 3;
    if (grayscale!=0) channel_count = 1;
    
    img.Resize(mshadow::Shape3(channel_count, res.rows, res.cols));
    for(index_t y = 0; y < img.size(1); ++y) {
      for(index_t x = 0; x < img.size(2); ++x) {
        cv::Vec3b bgr = res.at<cv::Vec3b>(y, x);
        if (!grayscale) { 
            // store in RGB order
            img[2][y][x] = bgr[0];
            img[1][y][x] = bgr[1];
            img[0][y][x] = bgr[2];
        }
        else {
            img[0][y][x] = bgr[0];
        }
      }
    }
    out.data = img;
    // free memory
    res.release();
    

    }
    ...

  3. winstywang commented on Jul 17, 2015

    @winstywang
    Contributor

    Hi @juliandewit Could you fix your coding style and submit a PR on this? I would like to merge it into master

  4. juliandewit commented on Jul 17, 2015

    @juliandewit

    Hello,
    Atm I made a very wild "practise download" for a kaggle competion I'm doing.
    I made a big mess of it but I learned a lot about the codebase.

    In a few days I intend to make a real fork and then I hope that I can contribute.

  5. winstywang commented on Jul 17, 2015

    @winstywang
    Contributor

    Thanks @juliandewit Good luck with your competition!

  6. haowu3 commented on Aug 18, 2015

    @haowu3
    Author

    Hi, @winstywang ,
    I added an as_grey option to img and imgrec iter. I can see the loss decreases while training so I guess it works.
    But then I found ImageAugmenter::Process looks to assume RGB images as well, is it true?

  7. haowu3 commented on Aug 20, 2015

    @haowu3
    Author

    Well, I found there are 3 functions of ImageAugmenter::Process(). The one which is actually called has no problem. The rest two may have problems but I'm not sure.

    Anyway, it seems to work. The PR is #229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions