THeParadigmShifter
THeParadigmShifter

Reputation: 23

Rewrite Image after applying sharpening filter to it

I have to sharpen an image and use it for further process.I found a code based on OpenCv which would do the work but instead of just displaying I want to save the image after applying the affects.Also this is just for a single image I want to apply for a folder of images. The sharpening code is below:

import cv2
import numpy as np
# Reading in and displaying our image
image = cv2.imread('images/input.jpg')
cv2.imshow('Original', image)
# Create our shapening kernel, it must equal to one eventually
kernel_sharpening = np.array([[-1,-1,-1], 
                              [-1, 9,-1],
                              [-1,-1,-1]])
# applying the sharpening kernel to the input image & displaying it.
sharpened = cv2.filter2D(image, -1, kernel_sharpening)
cv2.imshow('Image Sharpening', sharpened)
cv2.waitKey(0)
cv2.destroyAllWindows()

Upvotes: 1

Views: 904

Answers (2)

C. Fennell
C. Fennell

Reputation: 1032

According to the documentation:

Write an image Use the function cv2.imwrite() to save an image.

First argument is the file name, second argument is the image you want to save.

cv2.imwrite('messigray.png',img)

Upvotes: 0

Eypros
Eypros

Reputation: 5723

You can just use:

cv2.imwrite('images/input.jpg', image)

after

sharpened = cv2.filter2D(image, -1, kernel_sharpening)

and something like:

for im_path in im_paths:
   image = cv2.imread(im_path)
   ...

where you just replace your hardcoded path with im_path.

Anyway this is fundamental research, for example, and you should apply this before asking questions here.

Upvotes: 1

Related Questions