我有一些代码试图确定代码块的执行时间.
#include <time.h>
#include <stdio.h>
int main()
{
clock_t start_t, end_t, total_t;
int i;
start_t = clock(); //clock start
printf("Starting of the program, start_t = %ld\n", start_t);
printf("Going to scan a big loop, start_t = %ld\n", start_t);
for(i=0; i< 10000000; i++) //trying to determine execution time of this block
{
}
end_t = clock(); //clock stopped
printf("End of the big loop, end_t = %ld\n", end_t);
total_t = (long int)(end_t - start_t);
printf("Total time taken by CPU: %lu\n", total_t );
return(0); …Run Code Online (Sandbox Code Playgroud) 我正在使用Python与PIL和SciPy.我想从网络摄像头捕获图像,然后使用numpy和Scipy进一步处理它.有人可以帮我解决问题.
这里的代码有一个预定义的图像"lena",但我希望使用我自己捕获的图像而不是"lena"图像.我对代码做了哪些更改?
from scipy import misc
lena = misc.lena()
lx, ly = lena.shape
import matplotlib.pyplot as plt
crop_lena = lena[lx / 4: - lx / 4, ly / 4: - ly / 4]
plt.imshow(crop_lena)
Run Code Online (Sandbox Code Playgroud)
另一个例子
import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
import numpy as np
l = scipy.misc.lena()
plt.figure(figsize=(10, 3.6))
plt.subplot(131)
plt.imshow(l, cmap=plt.cm.gray)
plt.show()
Run Code Online (Sandbox Code Playgroud) 我试图在python中实现自适应直方图均衡.我拍摄一张图像并将其分割成较小的区域,然后将传统的直方图均衡应用于它.然后我将较小的图像合并为一个并获得最终的合成图像.最终图像在性质上看起来非常块状,并且对于每个单独的区域具有不同的对比度水平.有没有办法可以保持每个单独图像的均匀对比度,使其看起来像单个图像而不是缝合在一起的较小图像.
import cv2
import numpy as np
from matplotlib import pyplot as plt
from scipy.misc import imsave
from scipy import ndimage
from scipy import misc
import scipy.misc
import scipy
import image_slicer
from image_slicer import join
from PIL import Image
img = 'watch.png'
num_tiles = 25
tiles = image_slicer.slice(img, num_tiles)
for tile in tiles:
img = scipy.misc.imread(tile.filename)
hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf *hist.max()/ cdf.max()
plt.plot(cdf_normalized, color = 'g')
plt.hist(img.flatten(),256,[0,256], color = 'g')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper …Run Code Online (Sandbox Code Playgroud) 我正在使用Debian Linux和python 2.7.
我正在阅读图像并尝试处理它但我显示以下错误.有人可以告诉我我做错了什么吗?
import Image
import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
import numpy as np
from scipy import misc
import scipy.misc
img = scipy.misc.imread("/home/subhradeep/Desktop/test.jpg")
array=np.asarray(img)
plt.figure(figsize=(10, 3.6))
plt.subplot(131)
plt.imshow(array, cmap=plt.cm.gray)
plt.subplot(132)
plt.imshow(array, cmap=plt.cm.gray, vmin=10, vmax=100)
plt.axis('off')
plt.subplot(133)
plt.imshow(array, cmap=plt.cm.gray)
plt.contour(array, [160, 211])
plt.axis('off')
plt.subplots_adjust(wspace=0, hspace=0., top=0.99, bottom=0.01, left=0.05,right=0.99)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息
Traceback (most recent call last):
File "1saveimg.py", line 22, in <module>
plt.contour(array, [160, 211])
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2632, in contour
ret = ax.contour(*args, **kwargs)
File …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 python 中的图像切片器分割图像,然后对每个图像应用直方图均衡化并将它们组合回来。我能够将图像分成更小的块,我可以看到它们正在更新,但在将它们拼接在一起后,我最终得到了与原始图像相同的图像。有人可以指出我做错了什么。文件名为 watch.png
import cv2
import numpy as np
from matplotlib import pyplot as plt
from scipy.misc import imsave
# import scipy
from scipy import ndimage
from scipy import misc
import scipy.misc
import scipy
import sys
import argparse
import image_slicer
from image_slicer import join
img = 'watch.png'
num_tiles = 64
tiles = image_slicer.slice(img, num_tiles)
file = "watch"
k = 0
filelist =[]
for i in range(1,9):
for j in range(1,9):
filelist.insert(k, file+"_"+str(i).zfill(2)+"_"+str(j).zfill(2)+".png")
k=k+1
for i in range(0,num_tiles):
img = …Run Code Online (Sandbox Code Playgroud) python ×4
histogram ×2
numpy ×2
scipy ×2
c ×1
clock ×1
matplotlib ×1
python-2.7 ×1
system-clock ×1
time ×1
webcam ×1