Skip to content

Commit

Permalink
feat: connecting region growing and kmeans to the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamel-Mohammed committed May 3, 2023
1 parent 47e9759 commit f1fb12c
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 60 deletions.
66 changes: 43 additions & 23 deletions pages/page10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,10 @@ Page10::~Page10()
delete ui;
}

void Page10::on_input_image_label_clicked()
{
fileName = QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp *.jpeg)");
if (!fileName.isEmpty()) {
// read colored image
img = cv::imread(fileName.toStdString());
QImage qimage(img.data, img.cols, img.rows, QImage::Format_BGR888);
image = QPixmap::fromImage(qimage);
int w = ui->input_image_label->width();
int h = ui->input_image_label->height();
ui->input_image_label->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio));
ui->input_image_label->setScaledContents(true);
}
}


void Page10::on_applyBtn_clicked()
{
cv::Mat output(img.size(), img.type());
cv::Mat output(img.size(), img.type());
if(ui->type_comboBox->currentIndex()==0)
Segmentation::kmeansSegmentation(img, output, ui->kValueInput->value());
else if (ui->type_comboBox->currentIndex()==1)
Expand All @@ -44,26 +29,61 @@ void Page10::on_applyBtn_clicked()
Segmentation::agglomarativeSegmentation(img,output,ui->aggClusters->value(),ui->aggThreshold->value(),ui->aggProgressBar);
else if (ui->type_comboBox->currentIndex()==3)
{
// TODO: replace the dummy seeds
std::vector<cv::Point> seeds = {
cv::Point(100, 100),
cv::Point(700, 700)
};
Segmentation::regionGrowing(img, output, seeds, ui->thersholdValue->value());
cv::Mat inputImage = cv::imread(Img.toStdString(), cv::IMREAD_COLOR);
if(this->scene->seeds.size() > 0){
Segmentation::regionGrowing(inputImage, output, this->scene->seeds, ui->thersholdValue->value());
}
}
QImage qimage(output.data, output.cols, output.rows, QImage::Format_BGR888);
QPixmap Output = QPixmap::fromImage(qimage);
int w = ui->output_image_label->width();
int h = ui->output_image_label->height();
ui->output_image_label->setPixmap(Output.scaled(w,h,Qt::KeepAspectRatio));
ui->output_image_label->setScaledContents(true);
}

void Page10::on_inputLabel_clicked()
{
fileName = QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp *.jpeg)");
if (!fileName.isEmpty()) {
// read colored image
img = cv::imread(fileName.toStdString());
QImage qimage(img.data, img.cols, img.rows, QImage::Format_BGR888);
image = QPixmap::fromImage(qimage);
int w = ui->inputLabel->width();
int h = ui->inputLabel->height();
ui->inputLabel->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio));
ui->inputLabel->setScaledContents(true);
}
}


void Page10::on_type_comboBox_currentIndexChanged(int index)
{
ui->stackedWidget->setCurrentIndex(index);
if(index == 0 || index == 1 || index == 2){
ui->stackedWidget_2->setCurrentIndex(0);
}else{
ui->stackedWidget_2->setCurrentIndex(1);
}
ui->stackedWidget->setCurrentIndex(index);
}


void Page10::on_uploadImage_clicked()
{
Img= QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp *.jpeg)");
QImage image(Img);
scene = new Scene(true);
scene->setRad(5);
updateImage();
}

void Page10::updateImage(){
if (!Img.isEmpty()) {
QImage image(Img);
scene->addPixmap(QPixmap::fromImage(image));
ui->graphicsView->setScene(scene);
ui->graphicsView->fitInView(scene->sceneRect(),Qt::KeepAspectRatio);
}
}

12 changes: 9 additions & 3 deletions pages/page10.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include<CV/segmentation.h>
#include<QFileDialog>
#include<QLabel>
#include "utilities/scene.h"
#include <QGraphicsScene>

namespace Ui {
class Page10;
Expand All @@ -19,19 +21,23 @@ class Page10 : public QWidget
~Page10();

private slots:
void on_input_image_label_clicked();

void on_applyBtn_clicked();

void on_type_comboBox_currentIndexChanged(int index);

void on_inputLabel_clicked();

void on_uploadImage_clicked();

private:
Ui::Page10 *ui;
QPixmap image;
cv::Mat img;
QString fileName;
QString Img;
Scene* scene;
void rescaleImg(QLabel* imgSlot, QPixmap& image);

void updateImage();
};

#endif // PAGE10_H
99 changes: 67 additions & 32 deletions pages/page10.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,6 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Input</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="Clickable" name="input_image_label">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Output</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="output_image_label">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
Expand Down Expand Up @@ -257,6 +225,73 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Output</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="output_image_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Input</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QStackedWidget" name="stackedWidget_2">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Clickable" name="inputLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="uploadImage">
<property name="text">
<string>Upload Image</string>
</property>
</widget>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView">
<property name="cursor" stdset="0">
<cursorShape>CrossCursor</cursorShape>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
4 changes: 2 additions & 2 deletions pages/page5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void page5::on_upload_btn_clicked()
{
Img= QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp *.jpeg)");
QImage image(Img);
scene = new Scene();
scene = new Scene(false);
scene->setRad(ui->raduis->value());
updateImage();

Expand All @@ -53,7 +53,7 @@ void page5::on_raduis_valueChanged(int arg1)
{
scene->setRad(arg1);
updateImage();
scene->drawCircle();
scene->drawCircle(false);

}

Expand Down

0 comments on commit f1fb12c

Please sign in to comment.