Skip to content
Snippets Groups Projects
Commit 3eebd6ed authored by pjtka's avatar pjtka
Browse files

fillborder

parent 9ad54125
No related branches found
No related tags found
No related merge requests found
import numpy as np
import cv2
def fill_border(image, border_width):
dimension = 1
if len(image.shape)== 2:
y_height, x_height = image.shape
out_image = np.zeros((y_height + border_width * 2, x_height + border_width * 2, dimension))
y_height -= 1
x_height -= 1
else:
y_height, x_height, dimension = image.shape
out_image = np.zeros((y_height + border_width * 2, x_height + border_width * 2, dimension))
y_height -= 1
x_height -= 1
#border_width -= 1
border_mat = np.ones((border_width,border_width))
for i in range(dimension):
# Setting entire corners equal to corner values in image
out_image[:border_width,:border_width,i]=border_mat*image[0,0,i]
out_image[border_width+y_height+1:2*border_width+y_height+1,:border_width, i]=border_mat*image[y_height,0,i]
out_image[:border_width,border_width+x_height+1:2*border_width+x_height+1,i] =border_mat*image[0,x_height,i]
out_image[border_width+y_height+1:2*border_width+y_height+1,border_width+x_height+1:2*border_width+x_height+1,i]=border_mat*image[y_height,x_height,i]
# Setting the inner values equal to original image
out_image[border_width:border_width+y_height+1,border_width:border_width+x_height+1,i]=image[:,:,i]
# Copying and extending the values of the outer rows and columns of the original image
out_image[:border_width,border_width:border_width+x_height+1,i]= np.tile(image[0,:,i],(border_width,1))
out_image[border_width+y_height+1:2*border_width+y_height+1,border_width:border_width+x_height+1,i] = np.tile(image[y_height,:,i],(border_width,1))
out_image[border_width:border_width+y_height+1,:border_width,i]=np.transpose(np.tile(image[:,0,i],(border_width,1)))
out_image[border_width:border_width+y_height+1,border_width+x_height+1:2*border_width+x_height+1,i]=np.transpose(np.tile(image[:,x_height,i],(border_width,1)))
return out_image
test_matrix = np.random.normal(0,1,(10,10,1))
out_test = fill_border(test_matrix,3)
print(out_test)
print(out_test[:,-1])
import numpy as np
import argparse
import cv2
def max_rgb_filter(image):
# split the image into its BGR components
(B, G, R) = cv2.split(image)
# find the maximum pixel intensity values for each
# (x, y)-coordinate,, then set all pixel values less
# than M to zero
M = np.maximum(np.maximum(R, G), B)
R[R < M] = 0
G[G < M] = 0
B[B < M] = 0
# merge the channels back together and return the image
return cv2.merge([B, G, R])
# construct the argument parse and parse the arguments
image = cv2.imread(r'C:\Users\ptrkm\Downloads\Billedanalyse\Billedanalyse\Exercises\DTUSign1.jpg', 1)
filtered = max_rgb_filter(image)
cv2.imshow('image1',filtered)
cv2.waitKey(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment