Zadanie_03_ready
This commit is contained in:
parent
ca19e6fe34
commit
c618954323
@ -25,7 +25,7 @@ Histogram::~Histogram()
|
|||||||
void Histogram::generate(QImage* image)
|
void Histogram::generate(QImage* image)
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
qDebug() << Q_FUNC_INFO << " Generating histogram !";
|
||||||
for(int i = 0 ; i < image->height(); i++){
|
for(int i = 0 ; i < image->height(); i++){
|
||||||
for(int j = 0 ; j < image->width() ; j++){
|
for(int j = 0 ; j < image->width() ; j++){
|
||||||
QColor *clrCurrent = new QColor( image->pixel(i,j) );
|
QColor *clrCurrent = new QColor( image->pixel(i,j) );
|
||||||
@ -35,18 +35,88 @@ void Histogram::generate(QImage* image)
|
|||||||
L->insert(clrCurrent->alpha(),R->value(clrCurrent->alpha())+1);
|
L->insert(clrCurrent->alpha(),R->value(clrCurrent->alpha())+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the maximal value of the histogram in the given channel */
|
/** Returns the maximal value of the histogram in the given channel */
|
||||||
int Histogram::maximumValue(Channel selectedChannel = RGB)
|
int Histogram::maximumValue(Channel selectedChannel = RGB)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
int max = 0;
|
||||||
|
if(selectedChannel == LChannel){
|
||||||
|
return getMaxFromQHashHelper(get(selectedChannel));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
max = getMaxFromQHashHelper(R);
|
||||||
|
|
||||||
|
if(getMaxFromQHashHelper(G) > max){
|
||||||
|
max = getMaxFromQHashHelper(G);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getMaxFromQHashHelper(B) > max){
|
||||||
|
max = getMaxFromQHashHelper(B);
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return max or -1 when QHash is empty
|
||||||
|
int Histogram::getMaxFromQHashHelper( QHash<int, int> * channel ){
|
||||||
|
int max = -1;
|
||||||
|
|
||||||
|
QHash<int, int>::const_iterator iterator = channel->begin();
|
||||||
|
while (iterator != channel->end())
|
||||||
|
{
|
||||||
|
if(iterator.value() > max){
|
||||||
|
max = iterator.value();
|
||||||
|
}
|
||||||
|
++iterator;
|
||||||
|
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Histogram::getMaxKey( QHash<int, int> * channel ){
|
||||||
|
int max = -1;
|
||||||
|
|
||||||
|
QHash<int, int>::const_iterator iterator = channel->begin();
|
||||||
|
while (iterator != channel->end())
|
||||||
|
{
|
||||||
|
if(iterator.key() > max){
|
||||||
|
max = iterator.key();
|
||||||
|
}
|
||||||
|
++iterator;
|
||||||
|
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Histogram::getMinKey( QHash<int, int> * channel ){
|
||||||
|
int min = 256;
|
||||||
|
|
||||||
|
QHash<int, int>::const_iterator iterator = channel->begin();
|
||||||
|
while (iterator != channel->end())
|
||||||
|
{
|
||||||
|
if(iterator.key() < min){
|
||||||
|
min = iterator.key();
|
||||||
|
}
|
||||||
|
++iterator;
|
||||||
|
|
||||||
|
}
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return min or 256 when qhash is empty
|
||||||
|
int Histogram::getMinFromQHashHelper( QHash<int, int> * channel ){
|
||||||
|
int min = 256;
|
||||||
|
|
||||||
|
QHash<int, int>::const_iterator iterator = channel->begin();
|
||||||
|
while (iterator != channel->end())
|
||||||
|
{
|
||||||
|
if(iterator.value() < min){
|
||||||
|
min = iterator.value();
|
||||||
|
}
|
||||||
|
++iterator;
|
||||||
|
}
|
||||||
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,10 +16,15 @@ public:
|
|||||||
QHash<int, int>* get(Histogram::Channel);
|
QHash<int, int>* get(Histogram::Channel);
|
||||||
QImage getImage(Histogram::Channel, QBrush);
|
QImage getImage(Histogram::Channel, QBrush);
|
||||||
int maximumValue(Channel);
|
int maximumValue(Channel);
|
||||||
|
int getMaxFromQHashHelper( QHash<int, int> *);
|
||||||
|
int getMinFromQHashHelper( QHash<int, int> *);
|
||||||
|
int getMinKey( QHash<int, int> *);
|
||||||
|
int getMaxKey( QHash<int, int> *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generate(QImage*); // iterates all parent image pixels and set the Hashes
|
void generate(QImage*); // iterates all parent image pixels and set the Hashes
|
||||||
|
|
||||||
|
|
||||||
QHash<int, int>* R;
|
QHash<int, int>* R;
|
||||||
QHash<int, int>* G;
|
QHash<int, int>* G;
|
||||||
QHash<int, int>* B;
|
QHash<int, int>* B;
|
||||||
|
@ -14,13 +14,41 @@ HistogramStretching::HistogramStretching(PNM* img, ImageViewer* iv) :
|
|||||||
|
|
||||||
PNM* HistogramStretching::transform()
|
PNM* HistogramStretching::transform()
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "START";
|
||||||
int width = image->width();
|
int width = image->width();
|
||||||
int height = image->height();
|
int height = image->height();
|
||||||
|
|
||||||
PNM* newImage = new PNM(width, height, image->format());
|
PNM* newImage = new PNM(width, height, image->format());
|
||||||
|
Histogram * histogram = image->getHistogram();
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
int maxRed = histogram->getMaxKey(histogram->get(histogram->RChannel));
|
||||||
|
int minRed = histogram->getMinKey(histogram->get(histogram->RChannel));
|
||||||
|
|
||||||
|
int maxGreen = histogram->getMaxKey(histogram->get(histogram->GChannel));
|
||||||
|
int minGreen = histogram->getMinKey(histogram->get(histogram->GChannel));
|
||||||
|
|
||||||
|
int maxBlue = histogram->getMaxKey(histogram->get(histogram->BChannel));
|
||||||
|
int minBlue = histogram->getMinKey(histogram->get(histogram->BChannel));
|
||||||
|
|
||||||
|
int maxAlpha = histogram->getMaxKey(histogram->get(histogram->LChannel));
|
||||||
|
int minAlpha = histogram->getMinKey(histogram->get(histogram->LChannel));
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << "LOOP";
|
||||||
|
for(int x = 0 ; x < width; x++){
|
||||||
|
for (int y = 0 ; y < height; y++) {
|
||||||
|
|
||||||
|
QRgb pixel = image->pixel(x,y);
|
||||||
|
int g = (qGreen(pixel) - minGreen) * (MAX_VALUE/(maxGreen-minGreen));
|
||||||
|
int r = (qRed(pixel) - minRed) * (MAX_VALUE/(maxRed-minRed));
|
||||||
|
int b = (qBlue(pixel) - minBlue) * (MAX_VALUE/(maxBlue-minBlue));
|
||||||
|
// int a = (qAlpha(pixel) - minAlpha) * (MAX_VALUE/(maxAlpha-minAlpha));
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << "1. Here is working !!";
|
||||||
|
QRgb blee = QColor(r,g,b).rgba();
|
||||||
|
qDebug() << Q_FUNC_INFO << "2. Here is workingt too !!";
|
||||||
|
newImage->setPixel(x,y,QColor(r,g,b).rgba());
|
||||||
|
}
|
||||||
|
}
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
48
src/core/transformations/histogram_stretching.cpp.autosave
Normal file
48
src/core/transformations/histogram_stretching.cpp.autosave
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "histogram_stretching.h"
|
||||||
|
|
||||||
|
#include "../histogram.h"
|
||||||
|
|
||||||
|
HistogramStretching::HistogramStretching(PNM* img) :
|
||||||
|
Transformation(img)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HistogramStretching::HistogramStretching(PNM* img, ImageViewer* iv) :
|
||||||
|
Transformation(img, iv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PNM* HistogramStretching::transform()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "START";
|
||||||
|
int width = image->width();
|
||||||
|
int height = image->height();
|
||||||
|
|
||||||
|
PNM* newImage = new PNM(width, height, image->format());
|
||||||
|
Histogram * histogram = image->getHistogram();
|
||||||
|
|
||||||
|
int maxRed = histogram->getMaxKey(histogram->get(histogram->RChannel));
|
||||||
|
int minRed = histogram->getMinKey(histogram->get(histogram->RChannel));
|
||||||
|
|
||||||
|
int maxGreen = histogram->getMaxKey(histogram->get(histogram->GChannel));
|
||||||
|
int minGreen = histogram->getMinKey(histogram->get(histogram->GChannel));
|
||||||
|
|
||||||
|
int maxBlue = histogram->getMaxKey(histogram->get(histogram->BChannel));
|
||||||
|
int minBlue = histogram->getMinKey(histogram->get(histogram->BChannel));
|
||||||
|
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << "LOOP";
|
||||||
|
for(int x = 0 ; x < width; x++){
|
||||||
|
for (int y = 0 ; y < height; y++) {
|
||||||
|
|
||||||
|
QRgb pixel = image->pixel(x,y);
|
||||||
|
int g = (qGreen(pixel) - minGreen) * (MAX_VALUE/(maxGreen-minGreen));
|
||||||
|
int r = (qRed(pixel) - minRed) * (MAX_VALUE/(maxRed-minRed));
|
||||||
|
int b = (qBlue(pixel) - minBlue) * (MAX_VALUE/(maxBlue-minBlue));
|
||||||
|
newImage->setPixel(x,y,QColor(r,g,b).rgba());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
|||||||
class HistogramStretching : public Transformation
|
class HistogramStretching : public Transformation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
int const MAX_VALUE = 255;
|
||||||
HistogramStretching(PNM*);
|
HistogramStretching(PNM*);
|
||||||
HistogramStretching(PNM*, ImageViewer* iv);
|
HistogramStretching(PNM*, ImageViewer* iv);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user