@@ -300,51 +300,6 @@ def adjust_brightness(img, brightness_factor):
300300 return cv2 .LUT (img , table )
301301
302302
303- def adjust_hue (img , hue_factor ):
304- """Adjust hue of an image.
305- The image hue is adjusted by converting the image to HSV and
306- cyclically shifting the intensities in the hue channel (H).
307- The image is then converted back to original image mode.
308- `hue_factor` is the amount of shift in H channel and must be in the
309- interval `[-0.5, 0.5]`.
310- See `Hue`_ for more details.
311- .. _Hue: https://en.wikipedia.org/wiki/Hue
312- Args:
313- img (numpy ndarray): numpy ndarray to be adjusted.
314- hue_factor (float): How much to shift the hue channel. Should be in
315- [-0.5, 0.5]. 0.5 and -0.5 give complete reversal of hue channel in
316- HSV space in positive and negative direction respectively.
317- 0 means no shift. Therefore, both -0.5 and 0.5 will give an image
318- with complementary colors while 0 gives the original image.
319- Returns:
320- numpy ndarray: Hue adjusted image.
321- """
322- # After testing, found that OpenCV calculates the Hue in a call to
323- # cv2.cvtColor(..., cv2.COLOR_BGR2HSV) differently from PIL
324-
325- # This function takes 160ms! should be avoided
326- if not (- 0.5 <= hue_factor <= 0.5 ):
327- raise ValueError (
328- 'hue_factor is not in [-0.5, 0.5]. Got {}' .format (hue_factor ))
329- if not _is_numpy_image (img ):
330- raise TypeError ('img should be numpy Image. Got {}' .format (type (img )))
331- img = Image .fromarray (img )
332- input_mode = img .mode
333- if input_mode in {'L' , '1' , 'I' , 'F' }:
334- return np .array (img )
335-
336- h , s , v = img .convert ('HSV' ).split ()
337-
338- np_h = np .array (h , dtype = np .uint8 )
339- # uint8 addition take cares of rotation across boundaries
340- with np .errstate (over = 'ignore' ):
341- np_h += np .uint8 (hue_factor * 255 )
342- h = Image .fromarray (np_h , 'L' )
343-
344- img = Image .merge ('HSV' , (h , s , v )).convert (input_mode )
345- return np .array (img )
346-
347-
348303def adjust_gamma (img , gamma , gain = 1 ):
349304 r"""Perform gamma correction on an image.
350305 Also known as Power Law Transform. Intensities in RGB mode are adjusted
@@ -489,4 +444,4 @@ def radius_reduction(img, mask):
489444 '''
490445 叠加Mask,去除中值滤波灰色外缘
491446 '''
492- return cv2 .bitwise_and (img , img , mask = mask )
447+ return cv2 .bitwise_and (img , img , mask = mask )
0 commit comments