File size: 1,635 Bytes
daf0288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy.typing as npt
from numpy import uint8
import numpy as np
ImageType = npt.NDArray[uint8]
from typing import Tuple, List, Sequence, Optional, Union
import cv2
from PIL import Image
from PIL import ImageEnhance

def denoisingAndSharpening(images:List[ImageType]):

    new_images = []
    for img in images: 
        # Apply fastNlMeansDenoisingColored
        # Parameters:
        # - img: The input 8-bit 3-channel image.
        # - None: The output image (in-place if None is passed).
        # - h: Parameter regulating filter strength for luminance component. Higher h value removes noise better but also removes image details (10 is a good default value).
        # - hForColorComponents: The same as h but for color images only. For most images, 10 will be a good value.
        # - templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value is 7.
        # - searchWindowSize: Size in pixels of the window that is used to compute a weighted average for the given pixel. Should be odd. Recommended value is 21.
        h = 10
        hForColorComponents = 10
        templateWindowSize = 7
        searchWindowSize = 21

        img = cv2.fastNlMeansDenoisingColored(np.array(img), None, h, hForColorComponents, templateWindowSize, searchWindowSize)


        #cv2.imwrite(debug_folder+"denoisedAndHigherContrast.png",img)
        img = Image.fromarray(img).convert('RGB')
        enhancer = ImageEnhance.Contrast(img)
        img = enhancer.enhance(2)  # Increase contrast by a factor of 2
        
        new_images.append(img)
    return new_images