add 1
This commit is contained in:
1 parent
158a2ff3a0
commit
1186ca9b8a
9 files changed
+129
No files matched your search
@@ -0,0 +1,18 @@
|
||||
from matplotlib import pyplot as plt
|
||||
from PIL import Image
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
|
||||
pil_im = Image.open("images/house.jpg")
|
||||
pil_im1 = Image.open("images/house.jpg").convert("L")
|
||||
|
||||
plt.figure()
|
||||
plt.subplot(121)
|
||||
plt.title("原图")
|
||||
plt.axis("off")
|
||||
plt.imshow(pil_im)
|
||||
plt.subplot(122)
|
||||
plt.title("灰度图")
|
||||
plt.axis("off")
|
||||
plt.imshow(pil_im1, cmap="gray")
|
||||
plt.show()
|
||||
@@ -0,0 +1,28 @@
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def IsValidImage(img_path):
|
||||
bValid = True
|
||||
try:
|
||||
Image.open(img_path).verify()
|
||||
except:
|
||||
bValid = False
|
||||
return bValid
|
||||
|
||||
|
||||
def transimg(img_path):
|
||||
if IsValidImage(img_path):
|
||||
try:
|
||||
str = img_path.rsplit(".", 1)
|
||||
output_img_path = str[0] + ".jpg"
|
||||
print(output_img_path)
|
||||
im = Image.open(img_path)
|
||||
im.save(output_img_path)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
img_path = "images/lena.png"
|
||||
print(transimg(img_path))
|
||||
@@ -0,0 +1,27 @@
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from PIL import Image
|
||||
|
||||
im = np.array(Image.open("images/house.jpg").convert("L"))
|
||||
im2 = 255 - im
|
||||
print("对图像进行反向处理:\n", int(im.min()), int(im.max()))
|
||||
im3 = (100.0 / 255) * im + 100
|
||||
print("将图像像素值变换到100...200区间:\n", int(im3.min()), int(im3.max()))
|
||||
im4 = 255.0 * (im / 255.0) ** 2
|
||||
print("对像素值求平方后得到的图像:\n", int(im4.min()), int(im4.max()))
|
||||
|
||||
plt.figure()
|
||||
plt.gray()
|
||||
plt.subplot(131)
|
||||
plt.title("f(x) = 255 - x")
|
||||
plt.imshow(im2)
|
||||
plt.axis("off")
|
||||
plt.subplot(132)
|
||||
plt.title("f(x) = 100 / 255 * x + 100")
|
||||
plt.imshow(im3)
|
||||
plt.axis("off")
|
||||
plt.subplot(133)
|
||||
plt.title("f(x) = 255 * (x / 255) ^ 2")
|
||||
plt.imshow(im4)
|
||||
plt.axis("off")
|
||||
plt.show()
|
||||
@@ -0,0 +1,25 @@
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from matplotlib.font_manager import FontProperties
|
||||
from PIL import Image
|
||||
from scipy.ndimage import filters
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
im = np.array(Image.open("images/house.jpg").convert("L"))
|
||||
|
||||
plt.figure()
|
||||
plt.gray()
|
||||
plt.subplot(141)
|
||||
plt.title("原图")
|
||||
plt.axis("off")
|
||||
plt.imshow(im, cmap="gray")
|
||||
for bi, blur in enumerate([2, 4, 8]):
|
||||
im2 = np.zeros(im.shape)
|
||||
im2 = filters.gaussian_filter(im, blur) # type: ignore
|
||||
im2 = np.uint8(im2)
|
||||
imNum = str(blur)
|
||||
plt.subplot(1, 4, 2 + bi)
|
||||
plt.axis("off")
|
||||
plt.title("标准差为 " + imNum)
|
||||
plt.imshow(im2)
|
||||
plt.show()
|
||||
@@ -0,0 +1,31 @@
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from scipy.ndimage import filters
|
||||
from skimage.restoration import denoise_tv_chambolle
|
||||
|
||||
# import PCV.tools as rof
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
im = np.zeros((500, 500))
|
||||
im[100:400, 100:400] = 128
|
||||
im[200:300, 200:300] = 255
|
||||
im = im + 30 * np.random.standard_normal((500, 500))
|
||||
U = denoise_tv_chambolle(im, weight=0.1)
|
||||
# U, T = rof.denoise(im, im)
|
||||
G = filters.gaussian_filter(im, 10) # type: ignore
|
||||
|
||||
plt.figure()
|
||||
plt.gray()
|
||||
plt.subplot(131)
|
||||
plt.title("原噪声图像")
|
||||
plt.axis("off")
|
||||
plt.imshow(im)
|
||||
plt.subplot(132)
|
||||
plt.title("高斯模糊后的图像")
|
||||
plt.axis("off")
|
||||
plt.imshow(G)
|
||||
plt.subplot(133)
|
||||
plt.title("ROF 降噪后的图像")
|
||||
plt.axis("off")
|
||||
plt.imshow(U)
|
||||
plt.show()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 152 KiB |
Reference in new issue
Block a user