在python plot / image

时间:2016-06-15 14:18:19

标签: python image matlab python-2.7 plot

我想比较用Python获得的条形图(使用matplotlib)和Matlab中的函数图。为此,我考虑在条形图的图像上叠加Matlab图。

然而,我对matlab(python)也很陌生,所以我不知道如何做到这一点。我一直在查看有关此主题的几个问题,但我真的不明白我应该做些什么。

Bargraph from Python

A1 = 80;
A2 = 72;
B1 = 470;
B2 = 220;
D1 = 500;
D2 = 700;
T = 0.136994238205;
X = -60:0.1:60;
Y1 = A1*sqrt(D1*pi)*exp(-(X.^2)/(4*D1*T)) + B1*exp(-(X.^2)/(4*D1*T));

img = imread('bar2.png');

imagesc(X,Y1,flipud(img));
hold on;
plot(X,Y1,'r','linewidth',1.5);
set(gca, 'ydir', 'normal');

这是我尝试过的代码,但显然它不起作用,我刚刚尝试复制并理解其他问题中给出的代码。如何在条形图上添加此函数plot(X,Y1)?我知道我应该展示更多的编码工作,但我不知道如何解决这个问题并在网上我找不到任何有用的东西。我如何叠加?

有没有办法调整它,因为看起来我应该进行调整。 这就是我得到的 Plot over Bar Graph

1 个答案:

答案 0 :(得分:1)

如果您有两个图形(例如.png文件)并想要叠加图像,则使用blend()。下面的代码将所有图像叠加在“images2 /”文件夹中,并为您提供单个最终图像。

如果混合()更多图像,图像的质量(颜色,亮度,对比度)可能会下降。使用ImageEnhance可以提高图像质量。可以调整alpha的值以获得完美的混合。

import Image
import os
import cv2
import ImageEnhance
listing = os.listdir("images2/") 
new_img = Image.new("RGBA", (800, 600), "white") 

for file in listing:
    im = Image.open(path1 + file)  
    new_img = Image.blend(im, new_img, 2.0)
    new_img = Image.blend(new_img,im,0.5)

enhancer = ImageEnhance.Color(new_img)
new_img = enhancer.enhance(3)
enhancer = ImageEnhance.Contrast(new_img)
new_img = enhancer.enhance(2)
new_img.save("new008.png","PNG")