from __future__ import print_function import cv2 import numpy as np from helpers.image_reader import image_reader, show_image im1 = "/home/joemarshal/image_processing_opencv/images/resizedronaldo.jpg" mode = 1 img = image_reader(im1, mode) for alpha in np.arange(0, 1.1, 0.1)[::-1]: if alpha > 0.0: print("transparnet image", alpha) else: print("Not Transparent", alpha) overlay = img.copy() output = img.copy() cv2.rectangle(overlay, (420, 205), (595, 385), (0, 0, 255), -1) cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output) print("alpha{}, beta{}".format(alpha, 1 - alpha)) show_image(output)
import cv2 import numpy as np from helpers.image_reader import image_reader, show_image def hough_transform_image(image, img): """ :param image: pass the canny iamge :param img: pass the original image :return: it will mark the lines in the canny image and passes it back to the original image """ lines = cv2.HoughLinesP(image, 1, np.pi / 180, 50, maxLineGap=200) for line in lines: print(line) x1, x2, y1, y2 = line[0] cv2.line(img, (x1, x2), (y1, y2), (0, 255, 0), 3) show_image(img) return lines if __name__ == "__main__": img1 = "/home/joemarshal/image_processing_opencv/images/lines.png" mode = 0 image1 = image_reader(img1, 1) grey = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(grey, 75, 150) show_image(edges) hough = hough_transform_image(edges, image1)
import cv2 from helpers.image_reader import image_reader, show_image if __name__ == "__main__": img = "/home/joemarshal/image_processing_opencv/images/resizedronaldo.jpg" mode = cv2.WINDOW_NORMAL im = image_reader(img, mode) rows, columns = im.shape[:2] print(rows, columns) center = (rows / 2, columns / 2) rotating_image = cv2.getRotationMatrix2D(center, 570, 1.0) m = cv2.warpAffine(im, rotating_image, (columns, rows)) i = show_image(m)
""" Here you will find the code for low-pas-filter """ import cv2 from helpers.image_reader import image_reader, show_image def low_pass_filter(img): """ :param img: :return: """ fil = cv2.boxFilter(img, -1, (57, 57)) return fil if __name__ == "__main__": path = "/home/joemarshal/image_processing_opencv/images/shapes.jpg" mode = 1 ima = image_reader(path, mode) show_image(ima) con = cv2.cvtColor(ima, cv2.COLOR_BGR2RGB) show = low_pass_filter(con) show_image(show)
""" Here you can find how to add to images using the cv2.add() function """ import cv2 from helpers.image_reader import image_reader, show_image def add_image(image1, image2): """ :param image1: passing image1 :param image2: passing image 2 :return: adds both the images """ add = cv2.add(image1, image2) return add if __name__ == "__main__": img1 = "/home/joemarshal/image_processing/images/resizedronaldo.jpg" img2 = "/home/joemarshal/image_processing/images/resizedmessi.jpg" mode = 1 img1 = image_reader(img1, mode) img2 = image_reader(img2, mode) adding = add_image(img1, img2) show_image(adding)
import cv2 import matplotlib.pyplot as plt import numpy as np from helpers.image_reader import image_reader, show_image if __name__ == "__main__": im = "/home/joemarshal/image_processing_opencv/images/resizedronaldo.jpg" img = image_reader(im, 0) show_image(img) mask = np.zeros(img.shape[:2], np.uint8) mask[82:328, 31:338] = 255 masked_img = cv2.bitwise_and(img, img, mask=mask) show_image(masked_img) hist_full = plt.hist(img.ravel(), 256, [0, 256]) hist_mask = plt.hist(masked_img.ravel(), 256, [0, 256]) plt.xlim([0, 256]) plt.show()
""" Here you can run the threshold of an image without the threshold function """ import cv2 from helpers.image_reader import image_reader, show_image if __name__ == "__main__": img = "/home/joemarshal/image_processing_opencv/images/resizedronaldo.jpg" mode = cv2.IMREAD_COLOR im = image_reader(img, 0) print(im) print(im.shape) height, width = im.shape for h in range(height): for w in range(width): v = (im[h][w]) if v < 255: im[h][w] = 127 else: im[h][w] = 0 show_image(im)
def division(img1, img2): """ :param img1: pass image 1 :param img2: pass image 2 :return: returns the division of both the images """ return cv2.divide(img1, img2) if __name__ == "__main__": im1 = "/home/joemarshal/image_processing/images/resizedronaldo.jpg" im2 = "/home/joemarshal/image_processing/images/resizedmessi.jpg" mode = cv2.WINDOW_NORMAL image1 = image_reader(im1, mode) image2 = image_reader(im2, mode) show_image(image1) show_image(image2) bit_and = bitwise_and(image1, image2) bit_or = bitwise_or(image1, image2) bit_not = bitwise_not(image1, image2) bit_xor = bitwise_xor(image1, image2) subt = subtract(image1, image2) mul = multiplication(image1, image2) div = division(image1, image2) show_image(bit_and) show_image(bit_or) show_image(bit_not) show_image(bit_xor) show_image(subt)