I have the following code that generates a fractal image,
import numpy as np
import matplotlib.pyplot as plt
def julia(C):
X = np.arange(-1.5, 1.5, 0.2)
Y = np.arange(-1.5, 1.5, 0.2)
pixel = np.zeros((len(Y), len(X)))
for x_iter, x in enumerate(X):
for y_iter, y in enumerate(Y):
z = x + 1j * y
intensity = np.nan
r = np.empty((100, 100)) # Unused at the moment
for n in range(1, 1024):
if abs(z) > 2:
intensity = n
break
z = z**2 + C
pixel[y_iter, x_iter] = intensity
r.fill(intensity) # Unused at the moment
# We return pixel matrix
return pixel
# Compute Julia set image
pixel = julia(-0.7 + 0.27015j)
# Plotting
print(pixel[:,:])
data (pixel) as follow:
array([[ 1., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2.],
[ 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2.],
[ 2., 2., 2., 2., 2., 2., 2., 3., 3., 3., 3.,
3., 2., 2., 2.],
[ 2., 2., 2., 2., 3., 3., 3., 4., 5., 4., 4.,
3., 3., 3., 2.],
[ 2., 2., 3., 3., 3., 4., 4., 7., 209., 6., 5.,
4., 4., 3., 3.],
[ 2., 3., 3., 3., 4., 5., 6., 37., 59., 220., 13.,
7., 10., 6., 4.],
[ 3., 3., 4., 10., 7., 8., 9., 13., 408., 99., 126.,
401., 537., 437., 10.],
[ 3., 4., 6., 23., 40., 112., 68., 685., 48., 591., 567.,
290., 117., 353., 11.],
[ 4., 11., 353., 117., 290., 567., 591., 48., 685., 68., 112.,
40., 23., 6., 4.],
[ 4., 10., 437., 537., 401., 126., 99., 408., 13., 9., 8.,
7., 10., 4., 3.],
[ 3., 4., 6., 10., 7., 13., 220., 59., 37., 6., 5.,
4., 3., 3., 3.],
[ 2., 3., 3., 4., 4., 5., 6., 209., 7., 4., 4.,
3., 3., 3., 2.],
[ 2., 2., 3., 3., 3., 4., 4., 5., 4., 3., 3.,
3., 2., 2., 2.],
[ 2., 2., 2., 2., 3., 3., 3., 3., 3., 2., 2.,
2., 2., 2., 2.],
[ 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2.]])
after plotting the data (pixel), it looks as
plt.axis('off')
plt.imshow(pixel)
after obtaining the image and I did plt.savefig(), when I did image.open(), the data becomes as follows! I need to get rid of all the boundary unwanted white space that corresponding to all these 255 intensities
array([[[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
...,
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255]],
[[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
...,
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255]],
[[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
...,
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255]],
...,
[[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
...,
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255]],
[[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
...,
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255]],
[[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
...,
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255]]], dtype=uint16)
The white spaces around the image, which has to be gotten rid. I have to get rid of the white space that around the image for doing further image processing analysis, do you know how to write this code to the above code, please help!