I used an API to remove the background of a bunch of images. All the origin shape of the image with a wanted object is of size of (3000,3000). However, the API return some of image with only (500, 500). For the following research, I try to make the wanted object of black and the background of white in size of (3000,3000) and encounter the jagged problem.
I tried to resize the image in size of (500, 500) to (3000,3000) with interpolation and change the color, but it doesn't seem to improve the result:
mask_resize = cv2.resize(mask_img, (3000, 3000), interpolation=cv2.INTER_CUBIC) #resize the 500*500 to 3000*3000 with
white_area = np.all(mask_resize == [0,0,0], axis = 2)
black_area = np.all(mask_resize != [0,0,0], axis = 2)
img_new = img_origin.copy()
img_new[white_area] = [255,255,255] #black to white
img_new[black_area] = [0,0,0] #non-black to black
plt.imshow(img_new[0:500,1500:2000,:])