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

Getting black image! #28

Open
Coderx7 opened this issue Apr 4, 2017 · 7 comments
Open

Getting black image! #28

Coderx7 opened this issue Apr 4, 2017 · 7 comments

Comments

@Coderx7
Copy link

Coderx7 commented Apr 4, 2017

First of all thank you very much for this.
When I try to run your example code with these two images, I always get a black image!
buckskin_s_000005
buckskin_s_000331

This is the whole code which is given in the first page , I just replaced the random numpy array statement with these two images!:

import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np

im = caffe.io.load_image('buckskin_s_000331.png')
im2 = caffe.io.load_image('buckskin_s_000005.png')
images = np.zeros([2,32,32,3])
images[0] = im
images[1] = im2
# Sometimes(0.5, ...) applies the given augmenter in 50% of all cases,
# e.g. Sometimes(0.5, GaussianBlur(0.3)) would blur roughly every second image.
st = lambda aug: iaa.Sometimes(0.3, aug)

# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.
seq = iaa.Sequential([
        iaa.Fliplr(0.5), # horizontally flip 50% of all images
        iaa.Flipud(0.5), # vertically flip 50% of all images
        st(iaa.Superpixels(p_replace=(0, 1.0), n_segments=(20, 200))), # convert images into their superpixel representation
        st(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/width
        st(iaa.GaussianBlur((0, 3.0))), # blur images with a sigma between 0 and 3.0
        st(iaa.Sharpen(alpha=(0, 1.0), strength=(0.75, 1.5))), # sharpen images
        st(iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0))), # emboss images
        # search either for all edges or for directed edges
        st(iaa.Sometimes(0.5,
            iaa.EdgeDetect(alpha=(0, 0.7)),
            iaa.DirectedEdgeDetect(alpha=(0, 0.7), direction=(0.0, 1.0)),
        )),
        st(iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.2), per_channel=0.5)), # add gaussian noise to images
        st(iaa.Dropout((0.0, 0.1), per_channel=0.5)), # randomly remove up to 10% of the pixels
        st(iaa.Invert(0.25, per_channel=True)), # invert color channels
        st(iaa.Add((-10, 10), per_channel=0.5)), # change brightness of images (by -10 to 10 of original value)
        st(iaa.Multiply((0.5, 1.5), per_channel=0.5)), # change brightness of images (50-150% of original value)
        st(iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5)), # improve or worsen the contrast
        st(iaa.Affine(
            scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis
            translate_px={"x": (-16, 16), "y": (-16, 16)}, # translate by -16 to +16 pixels (per axis)
            rotate=(-45, 45), # rotate by -45 to +45 degrees
            shear=(-16, 16), # shear by -16 to +16 degrees
            order=ia.ALL, # use any of scikit-image's interpolation methods
            cval=(0, 255), # if mode is constant, use a cval between 0 and 255
            mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
        )),
        st(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)) # apply elastic transformations with random strengths
    ],
    random_order=True # do all of the above in random order
)

images_aug = seq.augment_images(images)
plt.imshow(images_aug[0])
plt.show()

image

what is wrong here?

@Coderx7
Copy link
Author

Coderx7 commented Apr 5, 2017

OK, I ran some more tests individually on each of those options, it seems onlyiaa.Fliplr(0.5)and iaa.Flipud(0.5) work. the rest result in a black image which I posted above!
What am I missing here?!
(By the way I'm on windows10.)

@aleju
Copy link
Owner

aleju commented Apr 5, 2017

caffe's load_image seems to return floats in the range 0-1.0, while the library usually expects uint8 in the range 0-255. So you would have to do something like (img*255).astype(np.uint8) after loading the images.
Considering your image size of 32x32, the number of augmenters is also rather large. You should probably decrease each augmenters probability by changing st = lambda aug: iaa.Sometimes(0.3, aug) to st = lambda aug: iaa.Sometimes(0.1, aug).
Further, you should use something like seq.show_grid(images[0], rows=8, cols=8) to show your augmenters results instead of plt.imshow(images_aug[0]), as the latter one will result in the same augmentation at every script run.

@Coderx7
Copy link
Author

Coderx7 commented Apr 5, 2017

@aleju : Thank you very much. The black image issue is gone.
and speaking of seg.show_grid(), it fails for me with this error RuntimeError: Could not execute image viewer.
I could'nt find a way to solve it, I have no idea whats causing this! so thats why I used the plt.imshow instead

@aleju
Copy link
Owner

aleju commented Apr 5, 2017

The threads that I can find sound like the command see must be available for misc.imshow to work (or an image viewer must be set in the environment variable SCIPY_PIL_IMAGE_VIEWER). I guess that command isn't available in Windows 10. Maybe I'll switch to OpenCV's imshow equivalent.

@Coderx7
Copy link
Author

Coderx7 commented Apr 5, 2017

I installed see through pip yet I still get the same error.

@aleju
Copy link
Owner

aleju commented Apr 5, 2017

I meant a command line program see, not a pypi package with that name, i.e. you must be able to type see in the command line and not get an error (that's how I understood it from the help threads - the program seems to be available on Ubuntu by default).

@wanghaisheng
Copy link

how to install the see program over mac os

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants