1

Libraries Imported:

    %matplotlib inline
    import numpy as np
    from scipy import misc
    import imageio
    import matplotlib.pyplot as plt
    from skimage import data

Like I created a:

    low_value_filter= dogs2 < 80

and did:

     dogs2[low_value_filter]=0 

so all the pixels in the image with pixel value less than 80 became black. I want to add the low_value_filter just to the right half of the image(or actually a specific range of pixels) instead of the full image. Below are images of a few attempts I made.

This is the image after adding a circular mask Low_value_filter to whole image Attempt 1Attempt 2Attempt 3

Edit:

     center_col= total_cols/2
  • do this: low_value_filter = np.zeros_like(dogs); low_value_filter[upper:lower, left:right] = dogs < 80; dogs[low_value_filter.astype(bool)] = 0 – yann ziselman Jul 12 '21 at 07:30
  • Hey, thats what i've done actually. The error i'm getting is: (boolean index did not match indexed array along dimension 1; dimension is 640 but corresponding boolean dimension is 320). Basically the shape of the image is 475,640,3 and on taking the right half (low_value_filter[upper:lower, left:right] = dogs < 80) on this step, the shape of low_value_filter is 475,320,3. – Ayush Phukan Jul 12 '21 at 19:21
  • Sorry, i made a mistake. Here's the fix: low_value_filter = np.zeros_like(dogs); low_value_filter[upper:lower, left:right] = dogs[upper:lower, left:right] < 80; dogs[low_value_filter.astype(bool)] = 0 – yann ziselman Jul 13 '21 at 05:41
  • did you notice the line ' low_value_filter = np.zeros_like(dogs);' ? this will make 'low_value_filter' have the same shape as your image. – yann ziselman Jul 13 '21 at 05:42
  • Hey @yannziselman. This worked. I got what you did. Thanks a lot mate!! – Ayush Phukan Jul 13 '21 at 07:16
  • you're welcome, you can post a self answer if you want – yann ziselman Jul 14 '21 at 07:31
  • Yes I will! @yannziselman – Ayush Phukan Jul 14 '21 at 20:03

1 Answers1

0

I've found the solution to this problem.

Create an array of zeros of the same shape as the image:

low_value_filter = np.zeros_like(dogs)

Select the range of the image you want to add your filter to:

low_value_filter[upper:lower, left:right] = dogs[upper:lower, left:right] < 80 (This will make the low_value_filter an array of 0's and 1's with respect to the range you've selected)

Now, just add the filter to your image as an index range of bool type and set it equal to whatever pixel value you want to (I've chosen 0 in this case)

dogs[low_value_filter.astype(bool)] = 0