mirror of
https://github.com/brmlab/medirap.git
synced 2025-06-08 00:54:00 +02:00
rework on slicing and thresholding
This commit is contained in:
parent
8039ff529a
commit
bc839e5d7c
5 changed files with 75 additions and 67 deletions
|
@ -4,16 +4,12 @@
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#define BLACK 0xFF000000
|
|
||||||
#define RED 0xFFFF0000
|
|
||||||
#define WHITE 0xFFFFFFFF
|
|
||||||
#define BLUE 0xFF0000FF
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->graphicsView->setScene(&scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -27,12 +23,11 @@ void MainWindow::on_pushLoad_clicked()
|
||||||
if (filename.isNull()) return;
|
if (filename.isNull()) return;
|
||||||
QFileInfo pathInfo(filename);
|
QFileInfo pathInfo(filename);
|
||||||
if (!vdata.load(pathInfo.path(), pathInfo.fileName())) {
|
if (!vdata.load(pathInfo.path(), pathInfo.fileName())) {
|
||||||
QMessageBox("Error", "Error loading data");
|
qDebug() << "Error loading data";
|
||||||
} else {
|
} else {
|
||||||
ui->sliderPosition->setMaximum(vdata.getDimZ());
|
ui->sliderPosition->setMaximum(vdata.getDimZ()-1);
|
||||||
ui->sliderPosition->setValue(vdata.getDimZ()/2);
|
ui->sliderPosition->setValue(vdata.getDimZ()/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -134,7 +129,31 @@ void MainWindow::floodfill(QImage &img)
|
||||||
void MainWindow::on_sliderPosition_valueChanged(int value)
|
void MainWindow::on_sliderPosition_valueChanged(int value)
|
||||||
{
|
{
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
|
if (ui->checkThreshold->checkState() != Qt::Unchecked) {
|
||||||
|
int threshold = ui->sliderThreshold->value();
|
||||||
|
QImage *img = new QImage(*vdata.getSlice(value));
|
||||||
|
for (int x = 0; x < img->width(); ++x) {
|
||||||
|
for (int y = 0; y < img->height(); ++y) {
|
||||||
|
img->setPixel(x,y, ((img->pixel(x,y) & 0xFF) > threshold) ? 255 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pixmap.convertFromImage(*img);
|
||||||
|
delete img;
|
||||||
|
} else {
|
||||||
|
pixmap.convertFromImage(*vdata.getSlice(value));
|
||||||
|
}
|
||||||
scene.clear();
|
scene.clear();
|
||||||
pixmap.convertFromImage(image);
|
|
||||||
scene.addPixmap(pixmap);
|
scene.addPixmap(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_sliderThreshold_valueChanged(int value)
|
||||||
|
{
|
||||||
|
if (ui->checkThreshold->checkState() != Qt::Unchecked) {
|
||||||
|
on_sliderPosition_valueChanged(ui->sliderPosition->value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_checkThreshold_clicked()
|
||||||
|
{
|
||||||
|
on_sliderPosition_valueChanged(ui->sliderPosition->value());
|
||||||
|
}
|
||||||
|
|
|
@ -22,10 +22,13 @@ private slots:
|
||||||
|
|
||||||
void on_sliderPosition_valueChanged(int value);
|
void on_sliderPosition_valueChanged(int value);
|
||||||
|
|
||||||
|
void on_sliderThreshold_valueChanged(int value);
|
||||||
|
|
||||||
|
void on_checkThreshold_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
VoxelData vdata;
|
VoxelData vdata;
|
||||||
QImage img;
|
|
||||||
QGraphicsScene scene;
|
QGraphicsScene scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>530</x>
|
<x>530</x>
|
||||||
<y>330</y>
|
<y>350</y>
|
||||||
<width>141</width>
|
<width>141</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
@ -72,45 +72,6 @@
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="pushAxis1">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>530</x>
|
|
||||||
<y>160</y>
|
|
||||||
<width>41</width>
|
|
||||||
<height>31</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>A-P</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="pushAxis2">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>580</x>
|
|
||||||
<y>160</y>
|
|
||||||
<width>41</width>
|
|
||||||
<height>31</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>D-V</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="pushAxis3">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>630</x>
|
|
||||||
<y>160</y>
|
|
||||||
<width>41</width>
|
|
||||||
<height>31</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>L-R</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QSlider" name="sliderPosition">
|
<widget class="QSlider" name="sliderPosition">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -159,7 +120,7 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QProgressBar" name="progressLoad_2">
|
<widget class="QProgressBar" name="progressSave">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>530</x>
|
<x>530</x>
|
||||||
|
@ -172,6 +133,35 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QLabel" name="labelSlice">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>530</x>
|
||||||
|
<y>180</y>
|
||||||
|
<width>141</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Slice:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QCheckBox" name="checkThreshold">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>530</x>
|
||||||
|
<y>330</y>
|
||||||
|
<width>141</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Active</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
|
|
@ -6,28 +6,23 @@
|
||||||
|
|
||||||
bool VoxelData::load(QString path, QString filename)
|
bool VoxelData::load(QString path, QString filename)
|
||||||
{
|
{
|
||||||
|
data.clear();
|
||||||
qDebug() << "Processing " + path + "/" + filename + " ...";
|
qDebug() << "Processing " + path + "/" + filename + " ...";
|
||||||
QFile file(path + "/" + filename);
|
QFile file(path + "/" + filename);
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
return false;
|
return false;
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
int z = 0;
|
|
||||||
data = new VOXELDATA[512*512*512];
|
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
QString line = in.readLine();
|
QString line = in.readLine();
|
||||||
QImage img;
|
|
||||||
qDebug() << "Loading " + line + " ...";
|
qDebug() << "Loading " + line + " ...";
|
||||||
img.load(path + "/" + line);
|
data.push_back(new QImage(path + "/" + line));
|
||||||
dimx = img.width();
|
|
||||||
dimy = img.height();
|
|
||||||
for (int x = 0; x < dimx; ++x) {
|
|
||||||
for (int y = 0; y < dimy; ++y) {
|
|
||||||
data[ x + y*512 + z*512*512] = img.pixel(x,y) & 0xFF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
z++;
|
|
||||||
}
|
}
|
||||||
dimz = z;
|
dimz = data.size();
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QImage *VoxelData::getSlice(int z)
|
||||||
|
{
|
||||||
|
return data[z];
|
||||||
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#define VOXELDATA_H
|
#define VOXELDATA_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QImage>
|
||||||
#define VOXELDATA unsigned char
|
#include <QVector>
|
||||||
|
|
||||||
class VoxelData
|
class VoxelData
|
||||||
{
|
{
|
||||||
|
@ -12,9 +12,10 @@ public:
|
||||||
inline int getDimY() { return dimy; }
|
inline int getDimY() { return dimy; }
|
||||||
inline int getDimZ() { return dimz; }
|
inline int getDimZ() { return dimz; }
|
||||||
bool load(QString path, QString filename);
|
bool load(QString path, QString filename);
|
||||||
|
const QImage *getSlice(int z);
|
||||||
private:
|
private:
|
||||||
int dimx, dimy, dimz;
|
int dimx, dimy, dimz;
|
||||||
VOXELDATA *data;
|
QVector<QImage *> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue