You can do the following to find the x limits and y limits of your transformed image:
plt.gca().set_aspect('equal')
i, j = np.where(np.all(r!=255, axis=2))
xlimits = j.min(), j.max()
ylimits = i.min(), i.max()
plt.xlim(xlimits)
plt.ylim(ylimits)
the set_aspect()
was added to show the image in its original aspect ratio. numpy.where()
will find the row and column indices where the image is not white (255, 255, 255), it is taking the minimum and maximum indices to set the new limits.