-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharttest.py
More file actions
108 lines (84 loc) · 3.79 KB
/
Copy pathcharttest.py
File metadata and controls
108 lines (84 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from PyQt6.QtGui import QBrush, QColor
from ..rangesliderside import RangeSlider
from PyQt6.QtCore import QMarginsF, QPoint, QRect
from PyQt6.QtCore import QPointF, QRectF, Qt
from PyQt6.QtWidgets import *
from PyQt6.QtCharts import QAreaSeries, QChart, QChartView,QLineSeries, QLogValueAxis, QValueAxis
from skimage.io import imread
from skimage.exposure import rescale_intensity
import numpy as np
import sys
class ChartWidget(QWidget):
def __init__(self,data):
super().__init__();
self.createObjects(data);
def createObjects(self,data):
self.chart = QChart();
line = QLineSeries(self.chart);
hist,bins = np.histogram(data,100);
for x,y in zip(bins,hist):
line.append(QPointF(x,y));
line.setName("Image Intensity");
self.chart.addSeries(line);
self.chart.setTitle("Image Pixel Intensity Histogram");
self.chart.legend().hide();
xAxis = QValueAxis();
xAxis.setRange(np.min(bins),np.max(bins));
xAxis.setTitleText("Intensity");
yAxis = QValueAxis();
yAxis.setRange(np.min(hist),np.max(hist));
yAxis.setTitleText("Frequency");
yAxis.setLabelsVisible(False)
self.chart.addAxis(xAxis,Qt.AlignmentFlag.AlignBottom);
self.chart.addAxis(yAxis,Qt.AlignmentFlag.AlignLeft);
line.attachAxis(xAxis);
line.attachAxis(yAxis);
slider = RangeSlider();
self.view = SliderChartView(self.chart,slider);
self.layout = QVBoxLayout();
self.layout.addWidget(self.view);
self.setLayout(self.layout);
#self.setFixedSize(500,500);
def resizeEvent(self, a0) -> None:
print(self.chart.rect());
print(self.chart.plotArea());
return super().resizeEvent(a0)
class SliderChartView(QChartView):
def __init__(self,chart,slider:RangeSlider,sliderHeight=None):
super().__init__(chart);
self.slider = slider;
self.slider.rangeChanged.connect(self.updateGraphClip)
self.scene().addWidget(self.slider);
self.leftRect = self.scene().addRect(QRectF(),QColor(0,0,0,128),QColor(0,0,0,128));
self.rightRect = self.scene().addRect(QRectF(),QColor(0,0,0,128),QColor(0,0,0,128));
if sliderHeight == None:
self.sliderHeight = self.slider.rect().height();
else:
self.sliderHeight = sliderHeight;
self.setMinimumSize(500,300);
def resizeEvent(self, event) -> None:
super().resizeEvent(event)
self.chart().resize(self.chart().size().shrunkBy(QMarginsF(0,0,0,self.sliderHeight)))
plotArea = self.chart().plotArea();
self.slider.setGeometry(QRect(plotArea.left(),self.chart().rect().bottom(),plotArea.width(),self.sliderHeight));
self.updateGraphClip();
def updateGraphClip(self):
plotArea:QRectF = self.chart().plotArea();
range = self.slider.max()-self.slider.min()
leftProportion = (self.slider.start()-self.slider.min())/(range);
rightProportion = (self.slider.end()-self.slider.min())/(range);
leftPos = leftProportion * plotArea.width() + plotArea.left();
rightPos = rightProportion * plotArea.width() + plotArea.left();
leftRect = QRectF(plotArea.topLeft(),QPointF(leftPos,plotArea.bottom()));
rightRect = QRectF(QPointF(rightPos,plotArea.top()),plotArea.bottomRight());
self.leftRect.setRect(leftRect);
self.rightRect.setRect(rightRect);
if __name__ == "__main__":
app = QApplication(sys.argv);
win = QMainWindow();
path = "C:/Users/hht/Downloads/062719_sample1/062719_Sample1_w1DIC_s1_t115.TIF"
image = imread(path);
image=rescale_intensity(image,in_range='dtype',out_range=(0,1));
win.setCentralWidget(ChartWidget(image.ravel()))
win.show();
sys.exit(app.exec());