user7733993
user7733993

Reputation: 3

Trying to resize an image that is printed out by matplotlib.pyplot

I am trying to use openCV in order to attain a black and white image of a picture, coloring in highly gradient pixels in white, and low gradient with black. I am currently using anaconda spyder and have been able to create the new image, but the image resolution is significantly lower than the image that I have supplied. Does anyone know how to resize an image produced by plt.imshow?

My code is as follows, and I have attached a picture.

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import cv2

image = mpimg.imread('exit-ramp.jpg')
plt.imshow(image)
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) #grayscale conversion
plt.imshow(gray, cmap='gray')

kernel_size = 3
blur_gray = cv2.GaussianBlur(gray, (kernel_size, kernel_size), 0)
lowthresh = 125
highthresh = 150
edges = cv2.Canny(blur_gray, lowthresh, highthresh)

plt.imshow(edges, cmap = 'Greys_r', aspect = 'auto')

output of my code

picture to take gradient of

Upvotes: 0

Views: 13239

Answers (1)

busybear
busybear

Reputation: 10580

You can define the figure size prior to plotting with the figsize attribute when defining a figure: plt.figure(figsize=(20, 4)).

Upvotes: 5

Related Questions