2021年2月7日星期日

Adding a 10px frame around a colored image

I am trying to add a 10 px boarder around my colored image. I have the following code to do that:

myRGB = mpimg.imread(" ")  plt.axis('off')  plt.imshow(myRGB)  plt.show()    
framed_color = np.zeros(np.add(myRGB.shape, tuple([20,20,0])))  framed_color[10:myRGB.shape[0]+10,10:myRGB.shape[1]+10] = myRGB  plt.axis('off')  plt.imshow(framed_color)    

After I run the code in the second chunk, my image become super bright, I cannot see the image, but the boarder is still here. I am able to do the boarder thing on gray image, because that case my tuple would be just 20,20, I don't need a third dimension.

I just want to know is there anyway to show image the way it supposed to be with boarder? Or it has to be gray image if I have to do it this way?

Thank you in advance!

https://stackoverflow.com/questions/66095102/adding-a-10px-frame-around-a-colored-image February 08, 2021 at 10:09AM

没有评论:

发表评论