Clean project.
@ -1,5 +0,0 @@
|
||||
# Rozwiązania laboratoria 01
|
||||
|
||||
# Znajdują się w katalogu ./01/do_sprawdzenia/cpp/mysimplegimp
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
QT += core gui widgets
|
||||
|
||||
TARGET = MySimpleGimp
|
||||
TEMPLATE = app
|
||||
|
||||
INCLUDEPATH += src/
|
||||
|
||||
SOURCES += src/main.cpp
|
||||
|
||||
include(src/core/core.pri)
|
||||
include(src/gui/gui.pri)
|
||||
|
||||
RESOURCES += res/icons.qrc
|
||||
|
||||
CONFIG += c++11
|
||||
OUTPUT += Console
|
||||
gcc:QMAKE_CXXFLAGS += -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable -Wno-reorder
|
||||
|
||||
msvc {
|
||||
QMAKE_CXXFLAGS_WARN_ON -= -W3
|
||||
QMAKE_CXXFLAGS_WARN_ON += -W2
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>icons/chart_curve.png</file>
|
||||
<file>icons/chart_curve_add.png</file>
|
||||
<file>icons/chart_curve_delete.png</file>
|
||||
<file>icons/chart_line_edit.png</file>
|
||||
<file>icons/door_out.png</file>
|
||||
<file>icons/eye.png</file>
|
||||
<file>icons/eye_blue.png</file>
|
||||
<file>icons/eye_gray.png</file>
|
||||
<file>icons/eye_green.png</file>
|
||||
<file>icons/eye_red.png</file>
|
||||
<file>icons/folder.png</file>
|
||||
<file>icons/things_digital.png</file>
|
||||
<file>icons/transform_rotate_90.png</file>
|
||||
<file>icons/transform_rotate_180.png</file>
|
||||
<file>icons/transform_rotate_270.png</file>
|
||||
<file>icons/transform_rotate.png</file>
|
||||
<file>icons/zoom_in.png</file>
|
||||
<file>icons/zoom_out.png</file>
|
||||
<file>icons/chart_curve_error.png</file>
|
||||
<file>icons/chart_curve_go.png</file>
|
||||
<file>icons/draw_convolve.png</file>
|
||||
<file>icons/lightbulb.png</file>
|
||||
<file>icons/checkerboard.png</file>
|
||||
<file>icons/filter.png</file>
|
||||
<file>icons/flag_airfield_vehicle_safety.png</file>
|
||||
<file>icons/zoom_extend.png</file>
|
||||
<file>icons/zoom_last.png</file>
|
||||
<file>icons/convert_color_to_gray.png</file>
|
||||
<file>icons/edge_detection.png</file>
|
||||
<file>icons/personal_finance.png</file>
|
||||
<file>icons/witch.png</file>
|
||||
<file>icons/arrow_in.png</file>
|
||||
<file>icons/arrow_out.png</file>
|
||||
<file>icons/document_shapes.png</file>
|
||||
<file>icons/key_a.png</file>
|
||||
<file>icons/key_b.png</file>
|
||||
<file>icons/key_c.png</file>
|
||||
<file>icons/key_d.png</file>
|
||||
<file>icons/key_e.png</file>
|
||||
<file>icons/key_f.png</file>
|
||||
<file>icons/key_g.png</file>
|
||||
<file>icons/key_i.png</file>
|
||||
<file>icons/key_j.png</file>
|
||||
<file>icons/key_k.png</file>
|
||||
<file>icons/key_l.png</file>
|
||||
<file>icons/key_m.png</file>
|
||||
<file>icons/key_n.png</file>
|
||||
<file>icons/key_o.png</file>
|
||||
<file>icons/key_p.png</file>
|
||||
<file>icons/key_q.png</file>
|
||||
<file>icons/key_s.png</file>
|
||||
<file>icons/key_t.png</file>
|
||||
<file>icons/key_u.png</file>
|
||||
<file>icons/key_v.png</file>
|
||||
<file>icons/key_w.png</file>
|
||||
<file>icons/key_x.png</file>
|
||||
<file>icons/key_y.png</file>
|
||||
<file>icons/key_z.png</file>
|
||||
<file>icons/arrow_divide.png</file>
|
||||
<file>icons/arrow_join.png</file>
|
||||
<file>icons/universal_binary.png</file>
|
||||
<file>icons/videodisplay.png</file>
|
||||
<file>icons/key_r.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 975 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1002 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1023 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB |
@ -1,87 +0,0 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
SOURCES += $$PWD/histogram.cpp \
|
||||
$$PWD/pnm.cpp \
|
||||
$$PWD/tools.cpp \
|
||||
$$PWD/transformations/transformation.cpp \
|
||||
$$PWD/transformations/bin_gradient.cpp \
|
||||
$$PWD/transformations/bin_iterbimodal.cpp \
|
||||
$$PWD/transformations/bin_manual.cpp \
|
||||
$$PWD/transformations/bin_niblack.cpp \
|
||||
$$PWD/transformations/bin_otsu.cpp \
|
||||
$$PWD/transformations/blur_gaussian.cpp \
|
||||
$$PWD/transformations/blur_linear.cpp \
|
||||
$$PWD/transformations/blur_uniform.cpp \
|
||||
$$PWD/transformations/conversion_grayscale.cpp \
|
||||
$$PWD/transformations/convolution.cpp \
|
||||
$$PWD/transformations/corner_harris.cpp \
|
||||
$$PWD/transformations/correction.cpp \
|
||||
$$PWD/transformations/edge_canny.cpp \
|
||||
$$PWD/transformations/edge_gradient.cpp \
|
||||
$$PWD/transformations/edge_laplacian.cpp \
|
||||
$$PWD/transformations/edge_laplacian_of_gauss.cpp \
|
||||
$$PWD/transformations/edge_prewitt.cpp \
|
||||
$$PWD/transformations/edge_roberts.cpp \
|
||||
$$PWD/transformations/edge_sobel.cpp \
|
||||
$$PWD/transformations/edge_zero.cpp \
|
||||
$$PWD/transformations/histogram_equalization.cpp \
|
||||
$$PWD/transformations/histogram_stretching.cpp \
|
||||
$$PWD/transformations/hough.cpp \
|
||||
$$PWD/transformations/hough_lines.cpp \
|
||||
$$PWD/transformations/hough_rectangles.cpp \
|
||||
$$PWD/transformations/map_height.cpp \
|
||||
$$PWD/transformations/map_horizon.cpp \
|
||||
$$PWD/transformations/map_normal.cpp \
|
||||
$$PWD/transformations/morph_dilate.cpp \
|
||||
$$PWD/transformations/morph_erode.cpp \
|
||||
$$PWD/transformations/morph_openclose.cpp \
|
||||
$$PWD/transformations/morphological_operator.cpp \
|
||||
$$PWD/transformations/negative_image.cpp \
|
||||
$$PWD/transformations/noise_bilateral.cpp \
|
||||
$$PWD/transformations/noise_median.cpp \
|
||||
$$PWD/transformations/segmentation.cpp
|
||||
|
||||
HEADERS += $$PWD/histogram.h \
|
||||
$$PWD/pnm.h \
|
||||
$$PWD/matrix/cmatrix \
|
||||
$$PWD/matrix/matrix.cc \
|
||||
$$PWD/matrix/matrix2.hxx \
|
||||
$$PWD/tools.h \
|
||||
$$PWD/transformations.h \
|
||||
$$PWD/transformations/transformation.h \
|
||||
$$PWD/transformations/bin_gradient.h \
|
||||
$$PWD/transformations/bin_iterbimodal.h \
|
||||
$$PWD/transformations/bin_manual.h \
|
||||
$$PWD/transformations/bin_niblack.h \
|
||||
$$PWD/transformations/bin_otsu.h \
|
||||
$$PWD/transformations/blur_gaussian.h \
|
||||
$$PWD/transformations/blur_linear.h \
|
||||
$$PWD/transformations/blur_uniform.h \
|
||||
$$PWD/transformations/conversion_grayscale.h \
|
||||
$$PWD/transformations/convolution.h \
|
||||
$$PWD/transformations/corner_harris.h \
|
||||
$$PWD/transformations/correction.h \
|
||||
$$PWD/transformations/edge_canny.h \
|
||||
$$PWD/transformations/edge_gradient.h \
|
||||
$$PWD/transformations/edge_laplacian.h \
|
||||
$$PWD/transformations/edge_laplacian_of_gauss.h \
|
||||
$$PWD/transformations/edge_prewitt.h \
|
||||
$$PWD/transformations/edge_roberts.h \
|
||||
$$PWD/transformations/edge_sobel.h \
|
||||
$$PWD/transformations/edge_zero.h \
|
||||
$$PWD/transformations/histogram_equalization.h \
|
||||
$$PWD/transformations/histogram_stretching.h \
|
||||
$$PWD/transformations/hough.h \
|
||||
$$PWD/transformations/hough_lines.h \
|
||||
$$PWD/transformations/hough_rectangles.h \
|
||||
$$PWD/transformations/map_height.h \
|
||||
$$PWD/transformations/map_horizon.h \
|
||||
$$PWD/transformations/map_normal.h \
|
||||
$$PWD/transformations/morph_dilate.h \
|
||||
$$PWD/transformations/morph_erode.h \
|
||||
$$PWD/transformations/morph_openclose.h \
|
||||
$$PWD/transformations/morphological_operator.h \
|
||||
$$PWD/transformations/negative_image.h \
|
||||
$$PWD/transformations/noise_bilateral.h \
|
||||
$$PWD/transformations/noise_median.h \
|
||||
$$PWD/transformations/segmentation.h
|
@ -1,84 +0,0 @@
|
||||
#include "histogram.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
Histogram::Histogram(QImage* image)
|
||||
{
|
||||
R = new QHash<int, int>;
|
||||
G = new QHash<int, int>;
|
||||
B = new QHash<int, int>;
|
||||
L = new QHash<int, int>;
|
||||
generate(image);
|
||||
}
|
||||
|
||||
Histogram::~Histogram()
|
||||
{
|
||||
delete R;
|
||||
delete G;
|
||||
delete B;
|
||||
delete L;
|
||||
}
|
||||
|
||||
void Histogram::generate(QImage* image)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
}
|
||||
|
||||
/** Returns the maximal value of the histogram in the given channel */
|
||||
int Histogram::maximumValue(Channel selectedChannel = RGB)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Returns a pointer to the given channel QHash<int, int> */
|
||||
QHash<int, int>* Histogram::get(Channel channel = LChannel)
|
||||
{
|
||||
if (channel==LChannel) return L;
|
||||
if (channel==RChannel) return R;
|
||||
if (channel==GChannel) return G;
|
||||
if (channel==BChannel) return B;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a 255 by 100 QImage containing a Histogram for the given channel.
|
||||
* The background is transparent (Alpha 0, RGB=255) */
|
||||
QImage Histogram::getImage(Channel channel = LChannel, QBrush pen = Qt::gray)
|
||||
{
|
||||
// Create blank QImage and fill it with transparent background:
|
||||
QImage histImage(255, 100, QImage::Format_ARGB32);
|
||||
histImage.fill(0);
|
||||
QPainter painter(&histImage);
|
||||
painter.setBrush(Qt::transparent);
|
||||
painter.setPen(Qt::transparent);
|
||||
painter.drawRect(0,0,255,100);
|
||||
|
||||
// Calculate the aspect ratio using the maximal value of the color histograms
|
||||
int maximum = (channel == LChannel ? maximumValue(LChannel) : maximumValue(RGB));
|
||||
float ratio = 100.0/float(maximum);
|
||||
|
||||
// Preparing the painter:
|
||||
painter.setBrush(pen);
|
||||
painter.setPen(pen.color());
|
||||
|
||||
int h;
|
||||
// Draw histogram
|
||||
QHash<int, int>* hist = get(channel);
|
||||
QHash<int, int>::const_iterator cit = hist->begin();
|
||||
|
||||
while (cit != hist->end())
|
||||
{
|
||||
h = 100 - floor(ratio*cit.value());
|
||||
painter.drawLine(cit.key(), h, cit.key(), 100);
|
||||
++cit;
|
||||
}
|
||||
|
||||
return histImage;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#ifndef HISTOGRAM_H
|
||||
#define HISTOGRAM_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QImage>
|
||||
|
||||
/** Class containing a histogram in form of four QHashes */
|
||||
class Histogram
|
||||
{
|
||||
public:
|
||||
enum Channel {RGB, RChannel, GChannel, BChannel, LChannel};
|
||||
|
||||
explicit Histogram(QImage *parent);
|
||||
~Histogram();
|
||||
|
||||
QHash<int, int>* get(Histogram::Channel);
|
||||
QImage getImage(Histogram::Channel, QBrush);
|
||||
int maximumValue(Channel);
|
||||
|
||||
private:
|
||||
void generate(QImage*); // iterates all parent image pixels and set the Hashes
|
||||
|
||||
QHash<int, int>* R;
|
||||
QHash<int, int>* G;
|
||||
QHash<int, int>* B;
|
||||
QHash<int, int>* L;
|
||||
};
|
||||
|
||||
#endif // HISTOGRAM_H
|
@ -1,51 +0,0 @@
|
||||
//////////////////////////////////////////////////////
|
||||
// Matrix TCL Pro 2.2
|
||||
// Copyright (c) 2000-2011 Techsoft. All Rights Reserved.
|
||||
// File name: CMatrix - The main header file to be included
|
||||
// Web: http://www.techsoftpl.com/matrix/
|
||||
//
|
||||
#ifndef _CMATRIX_12a08ba0_8940_11d3_910c_002018382069_INCLUDED
|
||||
#define _CMATRIX_12a08ba0_8940_11d3_910c_002018382069_INCLUDED
|
||||
|
||||
// For MFC projects in VC ++ !!!
|
||||
#if defined(max) || defined(min)
|
||||
#undef max
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
#if defined(abs)
|
||||
#undef abs
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <valarray>
|
||||
#include <complex>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define _TS_NO_MEMBER_TEMPLATES
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
#define RANGE_CHECK_
|
||||
#endif
|
||||
|
||||
#ifndef MAX_MATRIX_CACHE
|
||||
#define MAX_MATRIX_CACHE 4
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma option push -w-inl -w-pch
|
||||
#endif
|
||||
|
||||
#include "matrix2.hxx"
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma option pop
|
||||
#endif
|
||||
|
||||
#endif // _CMATRIX
|
||||
|
@ -1,525 +0,0 @@
|
||||
//////////////////////////////////////////////////////
|
||||
// Matrix TCL Pro 2.2
|
||||
// Copyright (c) 2000-2011 Techsoft . All Rights Reserved.
|
||||
// File name: Matrix.h - Header file for matrix class (do NOT include this file)
|
||||
// Web: http://www.techsoftpl.com/matrix/
|
||||
//
|
||||
#ifndef _MATRIX_H_12a08ba0_8940_11d3_910c_002018382069_INCLUDED
|
||||
#define _MATRIX_H_12a08ba0_8940_11d3_910c_002018382069_INCLUDED
|
||||
|
||||
namespace math {
|
||||
|
||||
using std::istream;
|
||||
using std::ostream;
|
||||
using std::valarray;
|
||||
using std::complex;
|
||||
using std::numeric_limits;
|
||||
using std::slice;
|
||||
using std::slice_array;
|
||||
using std::abs;
|
||||
using std::sqrt;
|
||||
using std::swap;
|
||||
using std::setw;
|
||||
|
||||
#ifdef RANGE_CHECK_
|
||||
using std::out_of_range;
|
||||
using std::invalid_argument;
|
||||
using std::runtime_error;
|
||||
using std::exception;
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
using ::ceil;
|
||||
using ::floor;
|
||||
using ::srand;
|
||||
using ::rand;
|
||||
using ::sqrt;
|
||||
using ::sqrtl;
|
||||
#else
|
||||
using std::ceil;
|
||||
using std::floor;
|
||||
using std::srand;
|
||||
using std::rand;
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
//////////////////
|
||||
// Temporary helping classes
|
||||
//
|
||||
class mslice;
|
||||
class gmslice;
|
||||
template <class T> class Mref;
|
||||
template <class T> class Cmat_iter;
|
||||
template <class T> class Mat_iter;
|
||||
template <class T> class mslice_matrix;
|
||||
template <class T> class gmslice_matrix;
|
||||
|
||||
enum MatArrayType { C_ARRAY, FORTRAN_ARRAY };
|
||||
|
||||
template <class T>
|
||||
class matrix
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef valarray<T> array_type;
|
||||
|
||||
// Constructors
|
||||
matrix ();
|
||||
matrix (size_t nRow, size_t nCol);
|
||||
matrix (size_t nRow, size_t nCol, const T& e);
|
||||
matrix (size_t nRow, size_t nCol, const T* Array, MatArrayType aType = C_ARRAY);
|
||||
matrix (size_t nRow, size_t nCol, const valarray<T>& vec);
|
||||
~matrix ();
|
||||
|
||||
// Copy constructors
|
||||
matrix (const matrix<T>& m);
|
||||
matrix (const mslice_matrix<T>& sm);
|
||||
matrix (const gmslice_matrix<T>& sm);
|
||||
#ifndef _TS_NO_MEMBER_TEMPLATES
|
||||
template <class X> matrix (const matrix<X>& m);
|
||||
#endif
|
||||
|
||||
// Assignment operators
|
||||
matrix<T>& operator= (const matrix<T>& m);
|
||||
matrix<T>& operator= (const mslice_matrix<T>& sm);
|
||||
matrix<T>& operator= (const gmslice_matrix<T>& sm);
|
||||
matrix<T>& operator= (const T& e);
|
||||
#ifndef _TS_NO_MEMBER_TEMPLATES
|
||||
template <class X> matrix<T>& operator= (const matrix<X>& m);
|
||||
#endif
|
||||
|
||||
size_t size () const throw() { return mPtr->nrow * mPtr->ncol; }
|
||||
size_t typesize () const throw() { return sizeof(T); }
|
||||
|
||||
size_t colsize () const throw() { return mPtr->nrow; } // No. of elements in a column, i.e., it's row number
|
||||
size_t rowsize () const throw() { return mPtr->ncol; } // No. of elements in a row, i.e., it's column number
|
||||
|
||||
size_t rowno () const throw() { return mPtr->nrow; } // No. of rows
|
||||
size_t colno () const throw() { return mPtr->ncol; } // No. of columns
|
||||
|
||||
void resize (size_t nRow, size_t nCol, const T& dval = T(0));
|
||||
void free ();
|
||||
|
||||
Mat_iter<T> row (size_t i);
|
||||
Cmat_iter<T> row (size_t i) const;
|
||||
Mat_iter<T> column (size_t i);
|
||||
Cmat_iter<T> column (size_t i) const;
|
||||
Mat_iter<T> diag (int i=0);
|
||||
Cmat_iter<T> diag (int i=0) const;
|
||||
T trace (int i=0) const;
|
||||
|
||||
Mat_iter<T> operator[] (size_t i) { return row(i); }
|
||||
Cmat_iter<T> operator[] (size_t i) const { return row(i); }
|
||||
Mat_iter<T> operator[] (int i) { return row(i); }
|
||||
Cmat_iter<T> operator[] (int i) const { return row(i); }
|
||||
|
||||
Mat_iter<T> operator() (size_t i) { return column(i); }
|
||||
Cmat_iter<T> operator() (size_t i) const { return column(i); }
|
||||
Mat_iter<T> operator() (int i) { return column(i); }
|
||||
Cmat_iter<T> operator() (int i) const { return column(i); }
|
||||
|
||||
Mref<T> operator() (size_t i, size_t j);
|
||||
const T& operator() (size_t i, size_t j) const;
|
||||
|
||||
mslice_matrix<T> operator[] (mslice ms);
|
||||
gmslice_matrix<T> operator[] (gmslice gm);
|
||||
|
||||
const matrix<T> operator[] (mslice ms) const;
|
||||
const matrix<T> operator[] (gmslice gm) const;
|
||||
|
||||
// Unary operators
|
||||
matrix<T> operator+ () const { return *this; }
|
||||
matrix<T> operator- () const;
|
||||
matrix<T> operator~ () const;
|
||||
matrix<T> operator! () const;
|
||||
|
||||
// Computed assignment
|
||||
matrix<T>& operator+= (const matrix<T>& m);
|
||||
matrix<T>& operator-= (const matrix<T>& m);
|
||||
matrix<T>& operator*= (const matrix<T>& m);
|
||||
matrix<T>& operator/= (const matrix<T>& m);
|
||||
matrix<T>& operator*= (const T& x);
|
||||
matrix<T>& operator/= (const T& x);
|
||||
|
||||
// Miscellaneous methods
|
||||
void null ();
|
||||
void unit ();
|
||||
void rand (int rmin=-1, int rmax=1, int rseed=0);
|
||||
|
||||
T sum () const { return mPtr->val.sum(); }
|
||||
T min () const { return mPtr->val.min(); }
|
||||
T max () const { return mPtr->val.max(); }
|
||||
|
||||
matrix<T> apply (T (*fn)(T)) const;
|
||||
matrix<T> apply (T (*fn)(const T&)) const;
|
||||
|
||||
matrix<T> apply (T (*fn)(size_t,size_t,T)) const;
|
||||
matrix<T> apply (T (*fn)(size_t,size_t,const T&)) const;
|
||||
|
||||
// Utility methods
|
||||
bool solve (const valarray<T>& v, valarray<T>& s) const;
|
||||
bool solve (const matrix<T>& v, matrix<T>& s) const;
|
||||
|
||||
matrix<T> adj () const;
|
||||
T cofact (size_t row, size_t col) const;
|
||||
|
||||
T det () const;
|
||||
T cond () const;
|
||||
size_t rank () const;
|
||||
|
||||
T norm1 () const;
|
||||
T norm2 () const;
|
||||
T normI () const;
|
||||
T normF () const;
|
||||
|
||||
bool lud (valarray<size_t>& ri, T* pDet = NULL);
|
||||
void lubksb (const valarray<size_t>& ri, const valarray<T>& v, valarray<T>& s) const;
|
||||
void lumpove (const matrix<T>& ludm, const valarray<size_t>& ri, const valarray<T>& v, valarray<T>& s) const;
|
||||
bool solve_lu (const valarray<T>& v, valarray<T>& s) const { return solve( v, s); }
|
||||
|
||||
bool inv ();
|
||||
bool inv_lu ();
|
||||
bool inv_sv ();
|
||||
bool inv_qr ();
|
||||
|
||||
bool svd (matrix<T>& vc, valarray<T>& w);
|
||||
void svbksb (const matrix<T>& vc, const valarray<T>& w, const valarray<T>& b, valarray<T>& x) const;
|
||||
bool solve_sv (const valarray<T>& v, valarray<T>& s) const;
|
||||
|
||||
void qrd (matrix<T>& r);
|
||||
void qrbksb (const matrix<T>& r, const valarray<T>& v, valarray<T>& s) const;
|
||||
bool solve_qr (const valarray<T>& v, valarray<T>& s) const;
|
||||
|
||||
bool chold ();
|
||||
void cholbksb (const valarray<T>& v, valarray<T>& s) const;
|
||||
bool solve_chol (const valarray<T>& v, valarray<T>& s) const;
|
||||
|
||||
bool eigen (valarray<T>& eival) const;
|
||||
bool eigen (valarray<T>& eival, matrix<T>& eivec) const;
|
||||
|
||||
bool eigen (valarray<T>& rev, valarray<T>& iev) const;
|
||||
bool eigen (valarray<T>& rev, valarray<T>& iev, matrix<T>& eivec) const;
|
||||
|
||||
// Type of matrices
|
||||
bool isSquare () const throw() { return (mPtr->nrow == mPtr->ncol); }
|
||||
bool isSingular () const;
|
||||
bool isDiagonal () const;
|
||||
bool isScalar () const;
|
||||
bool isUnit () const throw();
|
||||
bool isNull () const throw();
|
||||
bool isSymmetric () const;
|
||||
bool isSkewSymmetric () const;
|
||||
bool isUpperTriangular () const;
|
||||
bool isLowerTriangular () const;
|
||||
bool isRowOrthogonal () const;
|
||||
bool isColOrthogonal () const;
|
||||
|
||||
private:
|
||||
|
||||
struct base_mat
|
||||
{
|
||||
valarray<T> val;
|
||||
size_t nrow, ncol;
|
||||
int refcnt;
|
||||
|
||||
base_mat (size_t row, size_t col)
|
||||
: nrow( row), ncol( col), val( row * col) { refcnt = 1; }
|
||||
|
||||
base_mat (const T& v, size_t row, size_t col)
|
||||
: nrow( row), ncol( col), val( v, row * col) { refcnt = 1; }
|
||||
|
||||
base_mat (const T* v, size_t row, size_t col)
|
||||
: nrow( row), ncol( col), val( v, row * col) { refcnt = 1; }
|
||||
|
||||
base_mat (size_t row, size_t col, const valarray<T>& v)
|
||||
: nrow( row), ncol( col), val( v) { refcnt = 1; }
|
||||
|
||||
~base_mat () {;}
|
||||
};
|
||||
|
||||
base_mat *mPtr;
|
||||
enum AllocType { Allocate, Free, Record };
|
||||
|
||||
bool shared () { return (mPtr->refcnt > 1); }
|
||||
void clone ();
|
||||
base_mat *allocator (AllocType bOpt, size_t nrow = 0, size_t ncol = 0);
|
||||
|
||||
void tred2 (valarray<T>& d, valarray<T>& e, bool eivec);
|
||||
bool tql2 (valarray<T>& d, valarray<T>& e, bool eivec);
|
||||
void balanc (matrix<T>& v, bool eivec);
|
||||
bool hqr2 (valarray<T>& d, valarray<T>& e, matrix<T>& v, bool eivec);
|
||||
|
||||
friend class Mat_iter<T>;
|
||||
friend class Cmat_iter<T>;
|
||||
friend class Mref<T>;
|
||||
};
|
||||
|
||||
|
||||
/////////////
|
||||
// Non-member binary operators
|
||||
//
|
||||
template <class T> matrix<T> operator+ (const matrix<T>& m1, const matrix<T>& m2);
|
||||
template <class T> matrix<T> operator- (const matrix<T>& m1, const matrix<T>& m2);
|
||||
|
||||
template <class T> matrix<T> operator* (const matrix<T>& m1, const matrix<T>& m2);
|
||||
template <class T> matrix<T> operator* (const matrix<T>& m, const T& el);
|
||||
template <class T> matrix<T> operator* (const T& el, const matrix<T>& m);
|
||||
|
||||
template <class T> matrix<T> operator/ (const matrix<T>& m1, const matrix<T>& m2);
|
||||
template <class T> matrix<T> operator/ (const matrix<T>& m, const T& el);
|
||||
template <class T> matrix<T> operator/ (const T& el, const matrix<T>& m);
|
||||
|
||||
template <class T> valarray<T> operator* (const matrix<T>& m, const valarray<T>& v);
|
||||
template <class T> valarray<T> operator* (const valarray<T>& v, const matrix<T>& m);
|
||||
template <class T> valarray<T> operator/ (const matrix<T>& m, const valarray<T>& v);
|
||||
template <class T> valarray<T> operator/ (const valarray<T>& v, const matrix<T>& m);
|
||||
|
||||
template <class T> bool operator== (const matrix<T>& m1, const matrix<T>& m2);
|
||||
template <class T> bool operator!= (const matrix<T>& m1, const matrix<T>& m2);
|
||||
|
||||
|
||||
/////////////
|
||||
// Non-member functions
|
||||
//
|
||||
template <class T> matrix<T> pow (const matrix<T>& m, size_t n);
|
||||
template <class T> matrix<T> abs (const matrix<T>& m);
|
||||
template <class T> matrix<T> floor (const matrix<T>& m);
|
||||
template <class T> matrix<T> ceil (const matrix<T>& m);
|
||||
|
||||
template <class T> void mswap (const Mref<T>& x, const Mref<T>& y);
|
||||
template <class T> void mswap (const Mat_iter<T>& x, const Mat_iter<T>& y);
|
||||
template <class T> void mswap (matrix<T>& x, matrix<T>& y);
|
||||
|
||||
template <class T> istream& operator>> (istream& is, Mref<T> el);
|
||||
template <class T> istream& operator>> (istream& is, valarray<T>& v);
|
||||
template <class T> istream& operator>> (istream& is, Mat_iter<T> v);
|
||||
template <class T> istream& operator>> (istream& is, matrix<T>& m);
|
||||
|
||||
template <class T> ostream& operator<< (ostream& os, const Mref<T>& el);
|
||||
template <class T> ostream& operator<< (ostream &os, const valarray<T>& v);
|
||||
template <class T> ostream& operator<< (ostream& os, const Mat_iter<T>& v);
|
||||
template <class T> ostream& operator<< (ostream& os, const Cmat_iter<T>& v);
|
||||
template <class T> ostream& operator<< (ostream &os, const matrix<T>& m);
|
||||
|
||||
float epsilon (complex<float> v);
|
||||
double epsilon (complex<double> v);
|
||||
long double epsilon (complex<long double> v);
|
||||
|
||||
template <class T> T epsilon (const T& v);
|
||||
template <class T> bool isVecEq (const valarray<T>& v1, const valarray<T>& v2);
|
||||
|
||||
|
||||
//////////////////
|
||||
// Temporary helping classes
|
||||
//
|
||||
|
||||
template <class T>
|
||||
class Mref
|
||||
{
|
||||
public:
|
||||
Mref (matrix<T>& mm, size_t ii) : m(mm), i(ii) {;}
|
||||
|
||||
operator T () const { return m.mPtr->val[i]; }
|
||||
T* operator& () const { if (m.shared()) m.clone(); return &m.mPtr->val[i]; }
|
||||
|
||||
T& operator= (const Mref<T>& e) const { if (m.shared()) m.clone(); T te = e; return m.mPtr->val[i] = te; }
|
||||
T& operator= (const T& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] = e; }
|
||||
T& operator+= (const T& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] += e; }
|
||||
T& operator-= (const T& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] -= e; }
|
||||
T& operator*= (const T& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] *= e; }
|
||||
T& operator/= (const T& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] /= e; }
|
||||
|
||||
#ifndef _TS_NO_MEMBER_TEMPLATES
|
||||
template <class X> T& operator= (const X& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] = e; }
|
||||
template <class X> T& operator+= (const X& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] += e; }
|
||||
template <class X> T& operator-= (const X& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] -= e; }
|
||||
template <class X> T& operator*= (const X& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] *= e; }
|
||||
template <class X> T& operator/= (const X& e) const { if (m.shared()) m.clone(); return m.mPtr->val[i] /= e; }
|
||||
|
||||
template <class X> T operator+ (const X& e) { T y = *this; return y += e; }
|
||||
template <class X> T operator- (const X& e) { T y = *this; return y -= e; }
|
||||
template <class X> T operator* (const X& e) { T y = *this; return y *= e; }
|
||||
template <class X> T operator/ (const X& e) { T y = *this; return y /= e; }
|
||||
#endif
|
||||
|
||||
T operator++ () { if (m.shared()) m.clone(); return ++m.mPtr->val[i]; }
|
||||
T operator++ (int) { if (m.shared()) m.clone(); return m.mPtr->val[i]++; }
|
||||
T operator-- () { if (m.shared()) m.clone(); return --m.mPtr->val[i]; }
|
||||
T operator-- (int) { if (m.shared()) m.clone(); return m.mPtr->val[i]--; }
|
||||
|
||||
T operator+ () { return m.mPtr->val[i]; }
|
||||
T operator- () { return -m.mPtr->val[i]; }
|
||||
|
||||
Mref (const Mref& mr) : m(mr.m), i(mr.i) {;}
|
||||
private:
|
||||
Mref ();
|
||||
matrix<T>& m;
|
||||
size_t i;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class Cmat_iter
|
||||
{
|
||||
public:
|
||||
Cmat_iter (const matrix<T>& mm, const slice& ss) : m(mm), s(ss) {;}
|
||||
|
||||
const T& operator[] (size_t i) const;
|
||||
operator valarray<T> () const { return m.mPtr->val[s]; }
|
||||
size_t size () const { return s.size(); }
|
||||
|
||||
Cmat_iter(const Cmat_iter& mi) : m(mi.m), s(mi.s) {;}
|
||||
private:
|
||||
Cmat_iter();
|
||||
Cmat_iter& operator= (const Cmat_iter&);
|
||||
|
||||
const matrix<T>& m;
|
||||
slice s;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class Mat_iter
|
||||
{
|
||||
public:
|
||||
Mat_iter (matrix<T>& mm, const slice& ss) : m(mm), s(ss) {;}
|
||||
|
||||
Mref<T> operator[] (size_t i) const;
|
||||
operator valarray<T>() const { return m.mPtr->val[s]; }
|
||||
|
||||
void operator= (const valarray<T>& v) const;
|
||||
void operator= (const T& e) const;
|
||||
void operator*= (const valarray<T>& v) const;
|
||||
void operator/= (const valarray<T>& v) const;
|
||||
void operator+= (const valarray<T>& v) const;
|
||||
void operator-= (const valarray<T>& v) const;
|
||||
size_t size () const { return s.size(); }
|
||||
|
||||
Mat_iter(const Mat_iter& mi) : m(mi.m), s(mi.s) {;}
|
||||
private:
|
||||
Mat_iter();
|
||||
Mat_iter<T>& operator= (const Mat_iter<T>& mat);
|
||||
|
||||
matrix<T>& m;
|
||||
slice s;
|
||||
};
|
||||
|
||||
class mslice
|
||||
{
|
||||
public:
|
||||
mslice (size_t sRow, size_t sCol, size_t nRow, size_t nCol)
|
||||
: srow_(sRow), scol_(sCol), nrow_(nRow), ncol_(nCol) {;}
|
||||
mslice (const mslice& ms)
|
||||
: srow_(ms.srow_), scol_(ms.scol_),
|
||||
nrow_(ms.nrow_), ncol_(ms.ncol_) {;}
|
||||
|
||||
size_t size () const { return nrow_ * ncol_; }
|
||||
size_t start (size_t colno) const { return srow_*colno+scol_; }
|
||||
size_t end (size_t colno) const { return (srow_+nrow_-1)*colno+(scol_+ncol_); }
|
||||
|
||||
size_t colsize () const { return nrow_; }
|
||||
size_t rowsize () const { return ncol_; }
|
||||
|
||||
size_t rowno () const { return nrow_; }
|
||||
size_t colno () const { return ncol_; }
|
||||
|
||||
private:
|
||||
mslice ();
|
||||
size_t srow_,scol_, nrow_, ncol_;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class mslice_matrix
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
mslice_matrix (matrix<T>& mm, const mslice& ss)
|
||||
: s(ss), m(mm) {;}
|
||||
|
||||
const mslice& get_slice() const { return s; }
|
||||
matrix<T>& get_ref_mat () const { return m; }
|
||||
|
||||
void operator= (const matrix<T>& m2) const;
|
||||
void operator= (const T& e) const;
|
||||
void operator+= (const matrix<T>& m2) const;
|
||||
void operator-= (const matrix<T>& m2) const;
|
||||
void operator*= (const T& e) const;
|
||||
void operator/= (const T& e) const;
|
||||
|
||||
mslice_matrix (const mslice_matrix& ms) : s(ms.s), m(ms.m) {;}
|
||||
private:
|
||||
mslice_matrix ();
|
||||
mslice_matrix& operator= (const mslice_matrix&);
|
||||
|
||||
mslice s;
|
||||
matrix<T>& m;
|
||||
};
|
||||
|
||||
|
||||
enum MATIRX_TYPE { GENERAL, DIAGONAL, TRIDIAGONAL, UTRIANG, LTRIANG };
|
||||
|
||||
class gmslice
|
||||
{
|
||||
public:
|
||||
gmslice (MATIRX_TYPE mtype)
|
||||
: MType_(mtype), ncol_(0) {;}
|
||||
gmslice (size_t nCol, const valarray<size_t>& sRow, const valarray<size_t>& nRow)
|
||||
: MType_(GENERAL), ncol_(nCol), srow_(sRow), rsize_(nRow) {;}
|
||||
gmslice (const gmslice& gm)
|
||||
: MType_(gm.MType_), ncol_(gm.ncol_),
|
||||
srow_(gm.srow_), rsize_(gm.rsize_) {;}
|
||||
|
||||
size_t size () const { return srow_.size() * ncol_; }
|
||||
size_t start (size_t rowno) const { return srow_[rowno]; }
|
||||
size_t end (size_t rowno) const { return srow_[rowno]+rsize_[rowno]; }
|
||||
|
||||
size_t colsize () const { return srow_.size(); }
|
||||
size_t rowsize () const { return ncol_; }
|
||||
|
||||
size_t rowno () const { return srow_.size(); }
|
||||
size_t colno () const { return ncol_; }
|
||||
|
||||
MATIRX_TYPE getype() { return MType_; }
|
||||
|
||||
size_t ncol_;
|
||||
valarray<size_t> srow_,rsize_;
|
||||
|
||||
private:
|
||||
gmslice();
|
||||
MATIRX_TYPE MType_;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class gmslice_matrix
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
gmslice_matrix (matrix<T>& mm, const gmslice& ss)
|
||||
: s(ss), m(mm) {;}
|
||||
|
||||
const gmslice& get_slice() const { return s; }
|
||||
matrix<T>& get_ref_mat () const { return m; }
|
||||
|
||||
void operator= (const matrix<T>& m2) const;
|
||||
void operator= (const T& e) const;
|
||||
void operator+= (const matrix<T>& m2) const;
|
||||
void operator-= (const matrix<T>& m2) const;
|
||||
void operator*= (const T& e) const;
|
||||
void operator/= (const T& e) const;
|
||||
|
||||
gmslice_matrix (const gmslice_matrix& ms) : s(ms.s), m(ms.m) {;}
|
||||
private:
|
||||
gmslice_matrix ();
|
||||
gmslice_matrix& operator= (const gmslice_matrix&);
|
||||
|
||||
gmslice s;
|
||||
matrix<T>& m;
|
||||
};
|
||||
|
||||
|
||||
} // namespace math
|
||||
|
||||
#include "matrix.cc"
|
||||
|
||||
#endif // _MATRIX_H
|
@ -1,344 +0,0 @@
|
||||
#include "pnm.h"
|
||||
|
||||
#include "histogram.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
|
||||
|
||||
/** Creates a NULL QImage */
|
||||
PNM::PNM() :
|
||||
QImage()
|
||||
{
|
||||
histogram = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PNM image loaded from given path
|
||||
* @eg:
|
||||
PNM image1 = PNM("/home/file.pbm");
|
||||
PNM image2 = PNM("/home/file2.ppm");
|
||||
*/
|
||||
PNM::PNM(QString path) :
|
||||
QImage(path)
|
||||
{
|
||||
histogram = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PNM image from a QImage
|
||||
*/
|
||||
PNM::PNM(QImage img) :
|
||||
QImage(img), histogram(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new empty PNM with chosen QImage format
|
||||
*/
|
||||
PNM::PNM(int width, int height, QImage::Format format) :
|
||||
QImage(width, height, format), histogram(0)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case QImage::Format_Mono:
|
||||
break;
|
||||
case QImage::Format_Grayscale8:
|
||||
this->setColorCount(256);
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
this->setColor(i, qRgb(i, i, i));
|
||||
break;
|
||||
case QImage::Format_RGB32:
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Not supported image type!";
|
||||
}
|
||||
|
||||
this->fill(Qt::color0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a file from given path
|
||||
* Created to comply with PTO standard
|
||||
*/
|
||||
void PNM::loadFile(QString filename)
|
||||
{
|
||||
load(filename);
|
||||
}
|
||||
|
||||
PNM::~PNM()
|
||||
{
|
||||
if (histogram)
|
||||
delete histogram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a Image file in PNM format. This methods displays a Save File dialog
|
||||
* if mode is set the file is written using given mode. Otherwise Binary is used. */
|
||||
void PNM::saveFile(Mode mode = Binary)
|
||||
{
|
||||
QString filename = QFileDialog::getSaveFileName(
|
||||
0,
|
||||
"Save File",
|
||||
"hag_image.pbm",
|
||||
"Filetype (*.pbm);;Grayscale (*.pgm);;Policolor (*.ppm)");
|
||||
|
||||
QFileInfo fi(filename);
|
||||
if (mode == PNM::ASCII)
|
||||
{
|
||||
if (fi.suffix()== "pbm") saveTextPBM(filename);
|
||||
else if (fi.suffix()== "pgm") saveTextPGM(filename);
|
||||
else if(fi.suffix()== "ppm") saveTextPPM(filename);
|
||||
else qWarning() << "Wrong format selected!";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fi.suffix()== "pbm") saveBinPBM(filename);
|
||||
else if(fi.suffix()== "pgm") saveBinPGM(filename);
|
||||
else if(fi.suffix()== "ppm") saveBinPPM(filename);
|
||||
else qWarning() << "Wrong format selected!";
|
||||
}
|
||||
}
|
||||
|
||||
void PNM::saveTextPBM(QString filename)
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write("P1\n");
|
||||
file.write("# Created using PTO\n");
|
||||
file.write(QString("%1 %2\n").arg(width()).arg(height()).toLatin1());
|
||||
|
||||
for(int y = 0; y<height(); y++)
|
||||
{
|
||||
for(int x = 0; x<width(); x++)
|
||||
{
|
||||
int p = 0;
|
||||
if (qGray(pixel(x,y))<=127) p = 1;
|
||||
file.write(QString(" %1").arg(p).toLatin1());
|
||||
}
|
||||
file.write("\n");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void PNM::saveBinPBM(QString filename)
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
|
||||
// first part ascii
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write("P4\n");
|
||||
file.write("# Created using PTO\n");
|
||||
file.write(QString("%1 %2\n").arg(width()).arg(height()).toLatin1());
|
||||
|
||||
//second part binary
|
||||
|
||||
QDataStream out(&file);
|
||||
unsigned char byte = 0;
|
||||
unsigned char position = 0;
|
||||
|
||||
for(int y = 0; y<height(); y++)
|
||||
{
|
||||
for(int x = 0; x<width(); x++)
|
||||
{
|
||||
if (qGray(pixel(x,y)) <= 127)
|
||||
{
|
||||
byte = byte | (1 << (7-position));
|
||||
}
|
||||
|
||||
if (position == 7)
|
||||
{
|
||||
out << byte;
|
||||
byte = 0;
|
||||
}
|
||||
position = (position + 1) % 8;
|
||||
}
|
||||
|
||||
if (position != 0)
|
||||
{
|
||||
out << byte;
|
||||
}
|
||||
|
||||
byte = 0;
|
||||
position = 0;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void PNM::saveBinPGM(QString filename)
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
|
||||
// first part ascii
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write("P5\n");
|
||||
file.write("# Created using PTO\n");
|
||||
file.write(QString("%1 %2\n255\n").arg(width()).arg(height()).toLatin1());
|
||||
|
||||
//second part binary
|
||||
|
||||
QDataStream out(&file);
|
||||
for(int y = 0; y<height(); y++)
|
||||
{
|
||||
for(int x = 0; x<width(); x++)
|
||||
{
|
||||
out << ((unsigned char) qGray(pixel(x,y)));
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void PNM::saveBinPPM(QString filename)
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
|
||||
// first part ascii
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write("P6\n");
|
||||
file.write("# Created using PTO\n");
|
||||
file.write(QString("%1 %2\n255\n").arg(width()).arg(height()).toLatin1());
|
||||
|
||||
//second part binary
|
||||
|
||||
QDataStream out(&file);
|
||||
for(int y = 0; y<height(); y++)
|
||||
{
|
||||
for(int x = 0; x<width(); x++)
|
||||
{
|
||||
out << ((unsigned char) qRed(pixel(x,y)));
|
||||
out << ((unsigned char) qGreen(pixel(x,y)));
|
||||
out << ((unsigned char) qBlue(pixel(x,y)));
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
void PNM::saveTextPGM(QString filename) {
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write("P2\n");
|
||||
file.write("# Created using PTO\n");
|
||||
file.write(QString("%1 %2\n255\n").arg(width()).arg(height()).toLatin1());
|
||||
|
||||
for(int y = 0; y<height(); y++)
|
||||
{
|
||||
for(int x = 0; x<width(); x++)
|
||||
{
|
||||
file.write(QString(" %1").arg(qGray(pixel(x,y))).toLatin1());
|
||||
}
|
||||
file.write("\n");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void PNM::saveTextPPM(QString filename) {
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write("P3\n");
|
||||
file.write("# Created using PTO\n");
|
||||
file.write(QString("%1 %2\n255\n").arg(width()).arg(height()).toLatin1());
|
||||
|
||||
for(int y = 0; y<height(); y++)
|
||||
{
|
||||
for(int x = 0; x<width(); x++)
|
||||
{
|
||||
QRgb p = pixel(x,y);
|
||||
file.write(QString("%1 %2 %3 ").arg(qRed(p)).arg(qGreen(p)).arg(qBlue(p)).toLatin1());
|
||||
}
|
||||
file.write("\n");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a QByteArray containing a PNM image data in PPM format
|
||||
*/
|
||||
QByteArray* PNM::getData()
|
||||
{
|
||||
QByteArray* ba = new QByteArray();
|
||||
QBuffer buffer(ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
save(&buffer, "PPM");
|
||||
|
||||
return ba;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a uchar array containing a PNM image data in CMYK format
|
||||
*/
|
||||
uchar* PNM::getCMYK()
|
||||
{
|
||||
if(this->format() != QImage::Format_RGB32)
|
||||
{
|
||||
qWarning("Conversion to CMYK works only with color image!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uchar *bits = new uchar[this->width()*this->height()*4];
|
||||
|
||||
for(int i=0; i<this->width(); i++)
|
||||
{
|
||||
for(int j=0; j<this->height(); j++)
|
||||
{
|
||||
QRgb pixel = this->pixel(i, j);
|
||||
int R = qRed(pixel),
|
||||
G = qGreen(pixel),
|
||||
B = qBlue(pixel);
|
||||
double C,M,Y,K, var_K;
|
||||
|
||||
C = 1 - ( R / 255. );
|
||||
M = 1 - ( G / 255. );
|
||||
Y = 1 - ( B / 255. );
|
||||
var_K = 1;
|
||||
if ( C < var_K ) var_K = C;
|
||||
if ( M < var_K ) var_K = M;
|
||||
if ( Y < var_K ) var_K = Y;
|
||||
if ( var_K == 1 )
|
||||
{
|
||||
C = 0;
|
||||
M = 0;
|
||||
Y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
C = ( C - var_K ) / ( 1 - var_K );
|
||||
M = ( M - var_K ) / ( 1 - var_K );
|
||||
Y = ( Y - var_K ) / ( 1 - var_K );
|
||||
}
|
||||
K = var_K;
|
||||
|
||||
bits[i*this->width() + j*4] = (int) C*100;
|
||||
bits[i*this->width() + j*4 + 1] = (int) M*100;
|
||||
bits[i*this->width() + j*4 + 2] = (int) Y*100;
|
||||
bits[i*this->width() + j*4 + 3] = (int) K*100;
|
||||
}
|
||||
}
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
Histogram* PNM::getHistogram()
|
||||
{
|
||||
if (histogram)
|
||||
{
|
||||
return histogram;
|
||||
}
|
||||
else {
|
||||
histogram = new Histogram(this);
|
||||
return histogram;
|
||||
}
|
||||
}
|
||||
|
||||
QPoint PNM::center()
|
||||
{
|
||||
return QPoint(height()/2, width()/2);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#ifndef PNM_H
|
||||
#define PNM_H
|
||||
|
||||
class Histogram;
|
||||
|
||||
#include <QImage>
|
||||
|
||||
/* experimental support for Image Watch extension in Visual Studio 2013;
|
||||
* may be commented when compiling under QT Creator;
|
||||
*/
|
||||
//#if _MSC_VER == 1800 && _DEBUG
|
||||
//#include <QtGui/private/qimage_p.h>
|
||||
//#endif
|
||||
|
||||
/**
|
||||
* This is a PNM format extension for the QImage class of Qt
|
||||
* It gives the options of reading and saving PNM format specified images
|
||||
* from files. PNM implements both the ASCII and Binary formats of PNM
|
||||
* @see: http://en.wikipedia.org/wiki/Portable_anymap
|
||||
*/
|
||||
class PNM : public QImage
|
||||
{
|
||||
public:
|
||||
enum Mode {Binary, ASCII};
|
||||
|
||||
PNM();
|
||||
PNM(QString);
|
||||
PNM(QImage);
|
||||
PNM(int, int, QImage::Format);
|
||||
~PNM();
|
||||
|
||||
void loadFile(QString); // loads a file from given path
|
||||
void saveFile(Mode); // saves a file to using a PNM::Mode (ASCII or Binary)
|
||||
QPoint center();
|
||||
QByteArray* getData();
|
||||
uchar* getCMYK();
|
||||
Histogram* getHistogram();
|
||||
|
||||
private:
|
||||
// functions for saving the PNM file;
|
||||
// ASCII format:
|
||||
void saveTextPPM(QString);
|
||||
void saveTextPGM(QString);
|
||||
void saveTextPBM(QString);
|
||||
// Binary format:
|
||||
void saveBinPPM(QString);
|
||||
void saveBinPGM(QString);
|
||||
void saveBinPBM(QString);
|
||||
|
||||
Histogram* histogram;
|
||||
};
|
||||
|
||||
#endif // PNM_H
|
@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
|
||||
<UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" MenuName="Add to Image Watch"/>
|
||||
<Type Name="PNM">
|
||||
<UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" />
|
||||
</Type>
|
||||
|
||||
<Type Name="PNM">
|
||||
<Expand>
|
||||
<Synthetic Name="[type]">
|
||||
<DisplayString>UINT8</DisplayString>
|
||||
</Synthetic>
|
||||
<Synthetic Name="[channels]" Condition="d->format==5">
|
||||
<DisplayString>RGBA</DisplayString>
|
||||
</Synthetic>
|
||||
<Synthetic Name="[channels]" Condition="d->format==4">
|
||||
<DisplayString>RGBA</DisplayString>
|
||||
</Synthetic>
|
||||
<Synthetic Name="[channels]" Condition="d->format==3">
|
||||
<DisplayString>1</DisplayString>
|
||||
</Synthetic>
|
||||
<Item Name="[width]">d->width</Item>
|
||||
<Item Name="[height]">d->height</Item>
|
||||
<Item Name="[data]">d->data</Item>
|
||||
<Item Name="[stride]">d->bytes_per_line</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
</AutoVisualizer>
|
@ -1,700 +0,0 @@
|
||||
#include "tools.h"
|
||||
|
||||
#include "transformations.h"
|
||||
#include "gui/dialogs.h"
|
||||
#include "gui/toolsmenu.h"
|
||||
|
||||
Tools::Tools(ImageViewer* iv, QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
setViewer(iv);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 1 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::negativeImage()
|
||||
{
|
||||
ImageViewer* iv = getViewer(); // Get the ImageViewer which holds the image.
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
NegativeImage* ni = new NegativeImage(iv->getImage(), iv);
|
||||
ni->start();
|
||||
}
|
||||
|
||||
void Tools::convertToGrayScale()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
ConversionGrayscale* cg = new ConversionGrayscale(iv->getImage(), iv);
|
||||
cg->start();
|
||||
}
|
||||
|
||||
void Tools::correctBrightnessContrastGamma()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
|
||||
CorrectionDialog dialog;
|
||||
dialog.setImage(iv->getImage()->copy());
|
||||
dialog.update();
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
Correction* bc = new Correction(iv->getImage(), iv);
|
||||
bc->setParameter("shift", dialog.getShift());
|
||||
bc->setParameter("factor", dialog.getMultiplier());
|
||||
bc->setParameter("gamma", dialog.getGamma());
|
||||
|
||||
bc->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 2 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::histogramEqualize()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
HistogramEqualization* heq = new HistogramEqualization(iv->getImage(), iv);
|
||||
heq->start();
|
||||
}
|
||||
|
||||
void Tools::histogramStretch()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
HistogramStretching* hs = new HistogramStretching(iv->getImage(), iv);
|
||||
hs->start();
|
||||
}
|
||||
|
||||
void Tools::histogramShow()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (iv)
|
||||
iv->getHistogramWindow();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 3 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::blurGauss()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
GaussianDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
BlurGaussian* bg = new BlurGaussian(iv->getImage(), iv);
|
||||
bg->setParameter("size", dialog.getSize());
|
||||
bg->setParameter("sigma", dialog.getSigma());
|
||||
|
||||
bg->start();
|
||||
}
|
||||
|
||||
void Tools::blurLinear()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
LinearDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
BlurLinear* bl = new BlurLinear(iv->getImage(), iv);
|
||||
bl->setParameter("size", dialog.getSize());
|
||||
bl->setParameter("normalize", dialog.getNormalize());
|
||||
bl->setParameter("mask", dialog.getMask());
|
||||
|
||||
bl->start();
|
||||
}
|
||||
|
||||
void Tools::blurUniform()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
BlurUniform* bu = new BlurUniform(iv->getImage(), iv);
|
||||
bu->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 4 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::binGradient()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
BinarizationGradient* bg = new BinarizationGradient(iv->getImage(), iv);
|
||||
bg->start();
|
||||
}
|
||||
|
||||
void Tools::binIterBimodal()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
BinarizationIterBimodal* bim = new BinarizationIterBimodal(iv->getImage(), iv);
|
||||
bim->start();
|
||||
}
|
||||
|
||||
void Tools::binManual()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
SliderDialog dialog(new BinarizationManual(new PNM(iv->getImage()->copy())), "threshold");
|
||||
dialog.setRange(PIXEL_VAL_MIN, PIXEL_VAL_MAX);
|
||||
dialog.initSliderValue(PIXEL_VAL_MAX/2);
|
||||
dialog.setImage(iv->getImage()->copy());
|
||||
dialog.update();
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
BinarizationManual* bm = new BinarizationManual(iv->getImage(), iv);
|
||||
bm->setParameter("threshold", dialog.value());
|
||||
bm->start();
|
||||
}
|
||||
|
||||
void Tools::binNiblack()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
BinNiblackDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
BinarizationNiblack* bn = new BinarizationNiblack(iv->getImage(), iv);
|
||||
bn->setParameter("r", dialog.getR());
|
||||
bn->setParameter("a", dialog.getA());
|
||||
bn->start();
|
||||
}
|
||||
|
||||
void Tools::binOtsu()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
BinarizationOtsu* bo = new BinarizationOtsu(iv->getImage(), iv);
|
||||
bo->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 5 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::noiseMedian()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
NoiseMedianDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
NoiseMedian* nm = new NoiseMedian(iv->getImage(), iv);
|
||||
nm->setParameter("radius", dialog.getRadius());
|
||||
nm->start();
|
||||
}
|
||||
|
||||
void Tools::noiseBilateral()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
NoiseBilateralDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
NoiseBilateral* nb = new NoiseBilateral(iv->getImage(), iv);
|
||||
nb->setParameter("sigma_d", dialog.getSigmaD());
|
||||
nb->setParameter("sigma_r", dialog.getSigmaR());
|
||||
nb->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 6 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::morphDilate()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MorphDialog dialog;
|
||||
dialog.setWindowTitle("Dilate");
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
MorphDilate* md = new MorphDilate(iv->getImage(), iv);
|
||||
md->setParameter("size", dialog.getSize());
|
||||
md->setParameter("shape", (int)dialog.getShape());
|
||||
|
||||
md->start();
|
||||
}
|
||||
|
||||
void Tools::morphErode()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MorphDialog dialog;
|
||||
dialog.setWindowTitle("Erode");
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
MorphErode* me = new MorphErode(iv->getImage(), iv);
|
||||
me->setParameter("size", dialog.getSize());
|
||||
me->setParameter("shape", (int)dialog.getShape());
|
||||
|
||||
me->start();
|
||||
}
|
||||
|
||||
void Tools::morphOpen()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MorphDialog dialog;
|
||||
dialog.setWindowTitle("Open");
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
MorphOpenClose* mo = new MorphOpenClose(iv->getImage(), iv);
|
||||
mo->setParameter("size", dialog.getSize());
|
||||
mo->setParameter("shape", (int)dialog.getShape());
|
||||
mo->setParameter("type", (int)MorphOpenClose::Open);
|
||||
mo->start();
|
||||
}
|
||||
|
||||
void Tools::morphClose()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MorphDialog dialog;
|
||||
dialog.setWindowTitle("Close");
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
MorphOpenClose* mc = new MorphOpenClose(iv->getImage(), iv);
|
||||
mc->setParameter("size", dialog.getSize());
|
||||
mc->setParameter("shape", (int)dialog.getShape());
|
||||
mc->setParameter("type", (int)MorphOpenClose::Close);
|
||||
mc->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 7 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::edgeSobel()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
EdgeSobel* es = new EdgeSobel(iv->getImage(), iv);
|
||||
es->start();
|
||||
}
|
||||
|
||||
void Tools::edgePrewitt()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
EdgePrewitt* ep = new EdgePrewitt(iv->getImage(), iv);
|
||||
ep->start();
|
||||
}
|
||||
|
||||
void Tools::edgeRoberts()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
EdgeRoberts* er = new EdgeRoberts(iv->getImage(), iv);
|
||||
er->start();
|
||||
}
|
||||
|
||||
void Tools::edgeLaplacian()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MaskDialog dialog;
|
||||
dialog.setWindowTitle("Laplacian");
|
||||
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
EdgeLaplacian* el = new EdgeLaplacian(iv->getImage(), iv);
|
||||
el->setParameter("size", dialog.getSize());
|
||||
|
||||
el->start();
|
||||
}
|
||||
|
||||
void Tools::edgeZero()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
EdgeZeroDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
EdgeZeroCrossing* ezc = new EdgeZeroCrossing(iv->getImage(), iv);
|
||||
ezc->setParameter("size", dialog.getSize());
|
||||
ezc->setParameter("sigma", dialog.getSigma());
|
||||
ezc->setParameter("threshold", dialog.getThreshold());
|
||||
ezc->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 8 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::mapHeight()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MapHeight* mh = new MapHeight(iv->getImage(), iv);
|
||||
mh->start();
|
||||
}
|
||||
|
||||
void Tools::mapHorizon()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MapHorizonDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
MapHorizon* mh = new MapHorizon(iv->getImage(), iv);
|
||||
mh->setParameter("scale", dialog.getScale());
|
||||
mh->setParameter("alpha", dialog.getAlpha());
|
||||
mh->setParameter("direction", (int)dialog.getDirection());
|
||||
mh->start();
|
||||
}
|
||||
|
||||
void Tools::mapNormal()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
MapNormalDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
MapNormal* mn = new MapNormal(iv->getImage(), iv);
|
||||
mn->setParameter("strength", dialog.getStrength());
|
||||
mn->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 9 -------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::edgeCanny()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
EdgeCannyDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
EdgeCanny* ec = new EdgeCanny(iv->getImage(), iv);
|
||||
ec->setParameter("lower_threshold", dialog.getLowerThreshold());
|
||||
ec->setParameter("upper_threshold", dialog.getUpperThreshold());
|
||||
ec->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 10 ------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::houghTransform()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
|
||||
<< QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
HoughDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
Hough* hough = new Hough(iv->getImage(), iv);
|
||||
hough->setParameter("theta_density", dialog.getThetaDensity());
|
||||
hough->setParameter("skip_edge_detection", false);
|
||||
hough->start();
|
||||
}
|
||||
|
||||
void Tools::houghLines()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
HoughLinesDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
HoughLines* hl = new HoughLines(iv->getImage(), iv);
|
||||
hl->setParameter("threshold", dialog.getThreshold());
|
||||
hl->setParameter("draw_whole_lines", dialog.getDrawWholeLines());
|
||||
hl->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 11 ------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::cornerHarris()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
CornerHarrisDialog dialog;
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
CornerHarris* ch = new CornerHarris(iv->getImage(), iv);
|
||||
ch->setParameter("threshold", dialog.getThreshold());
|
||||
ch->setParameter("sigma", dialog.getSigma());
|
||||
ch->setParameter("sigma_weight", dialog.getSigmaWeight());
|
||||
ch->setParameter("k", dialog.getK());
|
||||
ch->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 12 ------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::houghRectangles()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
HoughRectangles* hr = new HoughRectangles(iv->getImage(), iv);
|
||||
hr->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ------------------------ LAB. 13 ------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
void Tools::segmentation()
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
|
||||
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
|
||||
<< QImage::Format_RGB32))
|
||||
return;
|
||||
|
||||
Segmentation* s = new Segmentation(iv->getImage(), iv);
|
||||
s->start();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* ----------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
void Tools::zoom(float factor)
|
||||
{
|
||||
ImageViewer* iv = getViewer();
|
||||
if (!iv)
|
||||
return;
|
||||
iv->zoom(factor);
|
||||
}
|
||||
|
||||
void Tools::rotate90()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Tools::rotate180()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Tools::rotate270()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
ImageViewer* Tools::getViewer()
|
||||
{
|
||||
return (m_iv->hasImage() ? m_iv : 0);
|
||||
}
|
||||
|
||||
void Tools::setViewer(ImageViewer* iv)
|
||||
{
|
||||
m_iv = iv;
|
||||
}
|
||||
|
||||
bool Tools::SupportedImageFormat(ImageViewer* iv,
|
||||
QList<QImage::Format> formats)
|
||||
{
|
||||
if (!iv)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < formats.size(); ++i)
|
||||
if (iv->getImage()->format() == formats.at(i))
|
||||
return true;
|
||||
|
||||
qWarning() << "Unsupported image type!";
|
||||
return false;
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
#ifndef TOOLS_H
|
||||
#define TOOLS_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QObject>
|
||||
|
||||
class ImageViewer;
|
||||
|
||||
class Tools : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(ImageViewer* imageViewer READ getViewer WRITE setViewer)
|
||||
public:
|
||||
explicit Tools(ImageViewer*, QObject *parent = 0);
|
||||
|
||||
ImageViewer* getViewer();
|
||||
void setViewer(ImageViewer*);
|
||||
bool SupportedImageFormat(ImageViewer*, QList<QImage::Format>);
|
||||
|
||||
public slots:
|
||||
|
||||
// lab. 1
|
||||
|
||||
void negativeImage();
|
||||
void convertToGrayScale();
|
||||
void correctBrightnessContrastGamma();
|
||||
|
||||
// lab. 2
|
||||
|
||||
void histogramEqualize();
|
||||
void histogramShow();
|
||||
void histogramStretch();
|
||||
|
||||
// lab. 3
|
||||
|
||||
void blurGauss();
|
||||
void blurLinear();
|
||||
void blurUniform();
|
||||
|
||||
// lab. 4
|
||||
|
||||
void binGradient();
|
||||
void binIterBimodal();
|
||||
void binManual();
|
||||
void binNiblack();
|
||||
void binOtsu();
|
||||
|
||||
// lab. 5
|
||||
|
||||
void noiseMedian();
|
||||
void noiseBilateral();
|
||||
|
||||
// lab. 6
|
||||
|
||||
void morphErode();
|
||||
void morphDilate();
|
||||
void morphOpen();
|
||||
void morphClose();
|
||||
|
||||
// lab. 7
|
||||
|
||||
void edgeSobel();
|
||||
void edgePrewitt();
|
||||
void edgeRoberts();
|
||||
void edgeLaplacian();
|
||||
void edgeZero();
|
||||
|
||||
// lab. 8
|
||||
|
||||
void mapHeight();
|
||||
void mapNormal();
|
||||
void mapHorizon();
|
||||
|
||||
// lab. 9
|
||||
|
||||
void edgeCanny();
|
||||
|
||||
// lab. 10
|
||||
|
||||
void houghTransform();
|
||||
void houghLines();
|
||||
|
||||
// lab. 11
|
||||
|
||||
void cornerHarris();
|
||||
|
||||
// lab. 12
|
||||
|
||||
void houghRectangles();
|
||||
|
||||
// lab. 13
|
||||
|
||||
void segmentation();
|
||||
|
||||
// display slots
|
||||
void rotate90();
|
||||
void rotate180();
|
||||
void rotate270();
|
||||
void zoom(float);
|
||||
|
||||
private:
|
||||
ImageViewer* m_iv;
|
||||
};
|
||||
|
||||
#endif // TOOLS_H
|
@ -1,38 +0,0 @@
|
||||
#ifndef TRANSFORMATIONS_H
|
||||
#define TRANSFORMATIONS_H
|
||||
|
||||
#include "transformations/bin_gradient.h"
|
||||
#include "transformations/bin_iterbimodal.h"
|
||||
#include "transformations/bin_manual.h"
|
||||
#include "transformations/bin_niblack.h"
|
||||
#include "transformations/bin_otsu.h"
|
||||
#include "transformations/blur_gaussian.h"
|
||||
#include "transformations/blur_linear.h"
|
||||
#include "transformations/blur_uniform.h"
|
||||
#include "transformations/convolution.h"
|
||||
#include "transformations/conversion_grayscale.h"
|
||||
#include "transformations/corner_harris.h"
|
||||
#include "transformations/correction.h"
|
||||
#include "transformations/edge_canny.h"
|
||||
#include "transformations/edge_laplacian.h"
|
||||
#include "transformations/edge_prewitt.h"
|
||||
#include "transformations/edge_roberts.h"
|
||||
#include "transformations/edge_sobel.h"
|
||||
#include "transformations/edge_zero.h"
|
||||
#include "transformations/histogram_equalization.h"
|
||||
#include "transformations/histogram_stretching.h"
|
||||
#include "transformations/hough.h"
|
||||
#include "transformations/hough_lines.h"
|
||||
#include "transformations/hough_rectangles.h"
|
||||
#include "transformations/map_height.h"
|
||||
#include "transformations/map_horizon.h"
|
||||
#include "transformations/map_normal.h"
|
||||
#include "transformations/morph_dilate.h"
|
||||
#include "transformations/morph_erode.h"
|
||||
#include "transformations/morph_openclose.h"
|
||||
#include "transformations/negative_image.h"
|
||||
#include "transformations/noise_bilateral.h"
|
||||
#include "transformations/noise_median.h"
|
||||
#include "transformations/segmentation.h"
|
||||
|
||||
#endif // TRANSFORMATIONS_H
|
@ -1,25 +0,0 @@
|
||||
#include "bin_gradient.h"
|
||||
|
||||
BinarizationGradient::BinarizationGradient(PNM* img) :
|
||||
Transformation(img)
|
||||
{
|
||||
}
|
||||
|
||||
BinarizationGradient::BinarizationGradient(PNM* img, ImageViewer* iv) :
|
||||
Transformation(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BinarizationGradient::transform()
|
||||
{
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
#ifndef BIN_GRADIENT_H
|
||||
#define BIN_GRADIENT_H
|
||||
|
||||
#include "transformation.h"
|
||||
|
||||
class BinarizationGradient : public Transformation
|
||||
{
|
||||
public:
|
||||
BinarizationGradient(PNM*);
|
||||
BinarizationGradient(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
#endif // BIN_GRADIENT_H
|
@ -1,30 +0,0 @@
|
||||
#include "bin_iterbimodal.h"
|
||||
|
||||
#include "conversion_grayscale.h"
|
||||
#include "histogram_equalization.h"
|
||||
#include "../histogram.h"
|
||||
|
||||
BinarizationIterBimodal::BinarizationIterBimodal(PNM* img) :
|
||||
Transformation(img)
|
||||
{
|
||||
}
|
||||
|
||||
BinarizationIterBimodal::BinarizationIterBimodal(PNM* img, ImageViewer* iv) :
|
||||
Transformation(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BinarizationIterBimodal::transform()
|
||||
{
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
#ifndef BIN_ITERBIMODAL_H
|
||||
#define BIN_ITERBIMODAL_H
|
||||
|
||||
#include "transformation.h"
|
||||
|
||||
class BinarizationIterBimodal : public Transformation
|
||||
{
|
||||
public:
|
||||
BinarizationIterBimodal(PNM*);
|
||||
BinarizationIterBimodal(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
#endif // BIN_ITERBIMODAL_H
|
@ -1,29 +0,0 @@
|
||||
#include "bin_manual.h"
|
||||
|
||||
BinarizationManual::BinarizationManual(PNM* img) :
|
||||
Transformation(img)
|
||||
{
|
||||
}
|
||||
|
||||
BinarizationManual::BinarizationManual(PNM* img, ImageViewer* iv) :
|
||||
Transformation(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BinarizationManual::transform()
|
||||
{
|
||||
int threshold = getParameter("threshold").toInt();
|
||||
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
#ifndef BIN_MANUAL_H
|
||||
#define BIN_MANUAL_H
|
||||
|
||||
#include "transformation.h"
|
||||
|
||||
class BinarizationManual : public Transformation
|
||||
{
|
||||
public:
|
||||
BinarizationManual(PNM*);
|
||||
BinarizationManual(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
#endif // BIN_MANUAL_H
|
@ -1,26 +0,0 @@
|
||||
#include "bin_niblack.h"
|
||||
|
||||
BinarizationNiblack::BinarizationNiblack(PNM* img) :
|
||||
Transformation(img)
|
||||
{
|
||||
}
|
||||
|
||||
BinarizationNiblack::BinarizationNiblack(PNM* img, ImageViewer* iv) :
|
||||
Transformation(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BinarizationNiblack::transform()
|
||||
{
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
int r = getParameter("r").toInt();
|
||||
double a = getParameter("a").toDouble();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return newImage;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef BIN_NIBLACK_H
|
||||
#define BIN_NIBLACK_H
|
||||
|
||||
#include "transformation.h"
|
||||
|
||||
class BinarizationNiblack : public Transformation
|
||||
{
|
||||
public:
|
||||
BinarizationNiblack(PNM*);
|
||||
BinarizationNiblack(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
#endif // BIN_NIBLACK_H
|
@ -1,27 +0,0 @@
|
||||
#include "bin_otsu.h"
|
||||
|
||||
#include "histogram_equalization.h"
|
||||
#include "../histogram.h"
|
||||
|
||||
BinarizationOtsu::BinarizationOtsu(PNM* img) :
|
||||
Transformation(img)
|
||||
{
|
||||
}
|
||||
|
||||
BinarizationOtsu::BinarizationOtsu(PNM* img, ImageViewer* iv) :
|
||||
Transformation(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BinarizationOtsu::transform()
|
||||
{
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef BIN_OTSU_H
|
||||
#define BIN_OTSU_H
|
||||
|
||||
#include "transformation.h"
|
||||
|
||||
class BinarizationOtsu : public Transformation
|
||||
{
|
||||
public:
|
||||
BinarizationOtsu(PNM*);
|
||||
BinarizationOtsu(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
|
||||
#endif // BIN_OTSU_H
|
@ -1,39 +0,0 @@
|
||||
#include "blur_gaussian.h"
|
||||
|
||||
BlurGaussian::BlurGaussian(PNM* img) :
|
||||
Convolution(img)
|
||||
{
|
||||
}
|
||||
|
||||
BlurGaussian::BlurGaussian(PNM* img, ImageViewer* iv) :
|
||||
Convolution(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BlurGaussian::transform()
|
||||
{
|
||||
emit message("Blurring...");
|
||||
|
||||
int size = getParameter("size").toInt();
|
||||
radius = (size/2)+1;
|
||||
sigma = getParameter("sigma").toDouble();
|
||||
|
||||
return convolute(getMask(size, Normalize), RepeatEdge);
|
||||
}
|
||||
|
||||
math::matrix<float> BlurGaussian::getMask(int size, Mode)
|
||||
{
|
||||
math::matrix<float> mask(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
float BlurGaussian::getGauss(int x, int y, float sigma)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
#ifndef BLUR_GAUSSIAN_H
|
||||
#define BLUR_GAUSSIAN_H
|
||||
|
||||
#include "convolution.h"
|
||||
|
||||
class BlurGaussian : public Convolution
|
||||
{
|
||||
public:
|
||||
BlurGaussian(PNM*);
|
||||
BlurGaussian(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
virtual math::matrix<float> getMask(int, Mode);
|
||||
static float getGauss(int, int, float);
|
||||
|
||||
private:
|
||||
int radius;
|
||||
double sigma;
|
||||
};
|
||||
|
||||
#endif // BLUR_GAUSSIAN_H
|
@ -1,24 +0,0 @@
|
||||
#include "blur_linear.h"
|
||||
|
||||
BlurLinear::BlurLinear(PNM* img) :
|
||||
Convolution(img)
|
||||
{
|
||||
}
|
||||
|
||||
BlurLinear::BlurLinear(PNM* img, ImageViewer* iv) :
|
||||
Convolution(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* BlurLinear::transform()
|
||||
{
|
||||
int maskSize = getParameter("size").toInt();
|
||||
QList<QVariant> tmpMask = getParameter("mask").toList();
|
||||
bool normalize = getParameter("normalize").toBool();
|
||||
|
||||
math::matrix<float> mask(maskSize, maskSize);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return convolute(mask, RepeatEdge);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef BLUR_LINEAR_H
|
||||
#define BLUR_LINEAR_H
|
||||
|
||||
#include "convolution.h"
|
||||
|
||||
class BlurLinear : public Convolution
|
||||
{
|
||||
public:
|
||||
BlurLinear(PNM*);
|
||||
BlurLinear(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
#endif // BLUR_LINEAR_H
|
@ -1,20 +0,0 @@
|
||||
#include "blur_uniform.h"
|
||||
|
||||
BlurUniform::BlurUniform(PNM* img) :
|
||||
Convolution(img)
|
||||
{
|
||||
}
|
||||
|
||||
BlurUniform::BlurUniform(PNM* img, ImageViewer* iv) :
|
||||
Convolution(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
math::matrix<float> BlurUniform::getMask(int size, Mode)
|
||||
{
|
||||
math::matrix<float> mask(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return mask;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef BLUR_UNIFORM_H
|
||||
#define BLUR_UNIFORM_H
|
||||
|
||||
#include "convolution.h"
|
||||
|
||||
class BlurUniform : public Convolution
|
||||
{
|
||||
public:
|
||||
BlurUniform(PNM*);
|
||||
BlurUniform(PNM*, ImageViewer*);
|
||||
|
||||
virtual math::matrix<float> getMask(int, Mode);
|
||||
};
|
||||
|
||||
#endif // BLUR_UNIFORM_H
|
@ -1,53 +0,0 @@
|
||||
#include "conversion_grayscale.h"
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
ConversionGrayscale::ConversionGrayscale(PNM* img) :
|
||||
Transformation(img)
|
||||
{
|
||||
}
|
||||
|
||||
ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) :
|
||||
Transformation(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
PNM* ConversionGrayscale::transform()
|
||||
{
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
|
||||
|
||||
if (image->format() == QImage::Format_Mono)
|
||||
{
|
||||
for (int x=0; x<width; x++){
|
||||
for (int y=0; y<height; y++)
|
||||
{
|
||||
QColor color = QColor::fromRgb(image->pixel(x,y)); // Getting the pixel(x,y) value
|
||||
newImage->setPixel(x,y, color == Qt::white ? PIXEL_VAL_MAX : PIXEL_VAL_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else // if (image->format() == QImage::Format_RGB32)
|
||||
{
|
||||
for (int x=0; x<width; x++)
|
||||
{
|
||||
for (int y=0; y<height; y++)
|
||||
{
|
||||
QRgb pixel = image->pixel(x,y); // Getting the pixel(x,y) value
|
||||
//int r = qRed(pixel); // Get the 0-255 value of the R channel
|
||||
//int g = qGreen(pixel); // Get the 0-255 value of the G channel
|
||||
//int b = qBlue(pixel);
|
||||
double r = qRed(pixel)*0.3;
|
||||
double g = qGreen(pixel)*0.6;
|
||||
double b = qBlue(pixel)*0.1;
|
||||
QColor newPixel = QColor(r+g+b,r+g+b,r+g+b);
|
||||
newImage->setPixel(x,y, newPixel.rgb());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef CONVERSION_GRAYSCALE_H
|
||||
#define CONVERSION_GRAYSCALE_H
|
||||
|
||||
#include "transformation.h"
|
||||
|
||||
class ConversionGrayscale : public Transformation
|
||||
{
|
||||
public:
|
||||
ConversionGrayscale(PNM*);
|
||||
ConversionGrayscale(PNM*, ImageViewer*);
|
||||
|
||||
virtual PNM* transform();
|
||||
};
|
||||
|
||||
#endif // CONVERSION_GRAYSCALE_H
|