<jupyter_start><jupyter_text>Selective Searchhttps://www.learnopencv.com/selective-search-for-object-detection-cpp-python/<jupyter_code># speed-up using multithreads
cv2.setUseOptimized(True);
cv2.setNumThreads(4);

# read image
im = img
# resize image
newHeight = 200
newWidth = int(im.shape[1]*200/im.shape[0])
im = cv2.resize(im, (newWidth, newHeight))    

# create Selective Search Segmentation Object using default parameters
ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()

# set input image on which we will run segmentation
ss.setBaseImage(im)

# Switch to fast but low recall Selective Search method
ss.switchToSelectiveSearchFast()

# Switch to high recall but slow Selective Search method
# ss.switchToSelectiveSearchQuality()


# run selective search segmentation on input image
rects = ss.process()
print('Total Number of Region Proposals: {}'.format(len(rects)))

# number of region proposals to show
numShowRects = 100
# increment to increase/decrease total number
# of reason proposals to be shown
increment = 50

# create a copy of original image
imOut = im.copy()

# itereate over all the region proposals
for i, rect in enumerate(rects):
    # draw rectangle for region proposal till numShowRects
    if (i < numShowRects):
        x, y, w, h = rect
        cv2.rectangle(imOut, (x, y), (x+w, y+h), (0, 255, 0), 1, cv2.LINE_AA)
    else:
        break

# show output
plt.imshow(imOut);

        
im_in = cv2.imread("nickel.jpg", cv2.IMREAD_GRAYSCALE);

# Threshold.
# Set values equal to or above 220 to 0.
# Set values below 220 to 255.
th, im_th = cv2.threshold(im_in, 220, 255, cv2.THRESH_BINARY_INV);

# Copy the thresholded image.
im_floodfill = im_th.copy()

# Mask used to flood filling.
# Notice the size needs to be 2 pixels than the image.
h, w = im_th.shape[:2]
mask = np.zeros((h+2, w+2), np.uint8)

# Floodfill from point (0, 0)
cv2.floodFill(im_floodfill, mask, (0,0), 255)
cv2.floodFill(im_floodfill, mask, (150,50), 127)

# Invert floodfilled image
im_floodfill_inv = cv2.bitwise_not(im_floodfill)

# Combine the two images to get the foreground.
im_out = im_th | im_floodfill_inv

# Display images.
plt.subplot(2,2,1)
plt.imshow(im_th, 'gray')
plt.title("Thresholded Image")

plt.subplot(2,2,2)
plt.imshow(im_floodfill, 'gray')
plt.title("Floodfilled Image")

plt.subplot(2,2,3)
plt.imshow(im_floodfill_inv, 'gray')
plt.title("Inverted Floodfilled Image")

plt.subplot(2,2,4)
plt.imshow(im_out, 'gray')
plt.title("Foreground");
im = cv2.imread("cow.jpg")
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)

# Edge preserving filter with two different flags.
imout = cv2.edgePreservingFilter(im, flags=cv2.RECURS_FILTER);
plt.subplot(2,3,1)
plt.imshow(imout)
plt.title("edge-preserving-recursive-filter")

imout = cv2.edgePreservingFilter(im, flags=cv2.NORMCONV_FILTER)
plt.subplot(2,3,2)
plt.imshow(imout)
plt.title("edge-preserving-normalized-convolution-filter")

# Detail enhance filter
imout = cv2.detailEnhance(im)
plt.subplot(2,3,3)
plt.imshow(imout)
plt.title("detail-enhance")

# Pencil sketch filter
imout_gray, imout = cv2.pencilSketch(im, sigma_s=60, sigma_r=0.07, shade_factor=0.05)
plt.subplot(2,3,4)
plt.imshow(imout_gray, 'gray')
plt.title("pencil-sketch")

plt.subplot(2,3,5)
plt.imshow(imout)
plt.title("pencil-sketch-color")

# Stylization filter
cv2.stylization(im,imout)
plt.subplot(2,3,6)
plt.imshow(imout)
plt.title("stylization");
def colormap_name(id) :
    switcher = {
        0 : "COLORMAP_AUTUMN",
        1 : "COLORMAP_BONE",
        2 : "COLORMAP_JET",
        3 : "COLORMAP_WINTER",
        4 : "COLORMAP_RAINBOW",
        5 : "COLORMAP_OCEAN",
        6 : "COLORMAP_SUMMER",
        7 : "COLORMAP_SPRING",
        8 : "COLORMAP_COOL",
        9 : "COLORMAP_HSV",
        10: "COLORMAP_PINK",
        11: "COLORMAP_HOT"

    }
    return switcher.get(id, "NONE")

im = cv2.imread("pluto.jpg", cv2.IMREAD_GRAYSCALE)
im_out = np.zeros((600, 800, 3), np.uint8);

for i in xrange(0,4) :
    for j in xrange(0,3) :
        k = i + j * 4
        im_color = cv2.applyColorMap(im, k)
        cv2.putText(im_color,
                    colormap_name(k), 
                    (30, 180), 
                    cv2.FONT_HERSHEY_DUPLEX, 
                    0.5, 
                    (255, 255, 255), 
                    1)

        ix200 = i * 200
        jx200 = j * 200

        im_out[ jx200 : jx200 + 200 , ix200 : ix200 + 200 , : ] = im_color

plt.imshow(im_out)
plt.title("Pseudo Colored");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12939866369710468, 'fraction_numerical': 0.043875278396436526, 'mean_word_length': 3.673257023933403, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '624483', 'license': 'MIT', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1699, 'n_words': 385, 'path': 'website/block_3_vision/misc/other_vision_stuff.ipynb', 'repo_name': 'MarsUniversity/ece387-robotics', 'size': '4490'}