Defines | Functions

picimage.cpp File Reference

#include <assert.h>
#include "texture.h"
#include "picimage.h"
#include <cmath>

Go to the source code of this file.

Defines

#define MASK_INTENSITIES(TYPE, PIC)
#define BINARY_INTENSITIES(TYPE, PIC)
#define LIMIT_INTENSITIES(TYPE, PIC)
#define PIC_IMAGE_PI   3.141592653589

Functions

template<class T >
void RGBtoHSI (T *RGB, T *HSI)
template<class T >
void HSItoRGB (T *HSI, T *RGB)

Define Documentation

#define BINARY_INTENSITIES (   TYPE,
  PIC 
)
Value:
{                                                                       \
TYPE* source = (TYPE *) src;                                            \
unsigned char* dest = dst;                                              \
register float a;                                                       \
if (model () == INTENSITY)                                              \
while (dest < eol) {                                                    \
a = source [0] * scale - bias;                                          \
*dest = (a > 255.0 ? 255 : (a < 0.0 ? 0 : 255));                        \
source++;                                                               \
dest++;                                                                 \
} else                                                                  \
if (model () == INTENSITY_ALPHA)                                        \
while (dest < eol) {                                                    \
a = source [0] * scale - bias;                                          \
dest [0] = (a > 255.0 ? 255 : (a < 0.0 ? 0 : 255));                     \
dest [1] = (a > 0.0 ? 255 : 0);                                         \
source++;                                                               \
dest += 2;                                                              \
}                                                                       \
}

Definition at line 235 of file picimage.cpp.

Referenced by iil4mitkPicImage::copyImage().

#define LIMIT_INTENSITIES (   TYPE,
  PIC 
)

Definition at line 257 of file picimage.cpp.

Referenced by iil4mitkPicImage::copyImage().

#define MASK_INTENSITIES (   TYPE,
  PIC 
)
Value:
{                                                                       \
TYPE* source = (TYPE *) src;                                            \
unsigned char* dest = dst;                                              \
register float a;                                                       \
if (model () == INTENSITY)                                              \
while (dest < eol) {                                                    \
a = source [0] * scale - bias;                                          \
*dest = (a > 255.0 ? 0 : (a < 0.0 ? 0 : 255));                          \
source++;                                                               \
dest++;                                                                 \
} else                                                                  \
if (model () == INTENSITY_ALPHA)                                        \
while (dest < eol) {                                                    \
a = source [0] * scale - bias;                                          \
dest [1] = dest [0] = (a > 255.0 ? 0 : (a < 0.0 ? 0 : 255));            \
source++;                                                               \
dest += 2;                                                              \
}                                                                       \
}

Definition at line 214 of file picimage.cpp.

Referenced by iil4mitkPicImage::copyImage().

#define PIC_IMAGE_PI   3.141592653589

Definition at line 402 of file picimage.cpp.

Referenced by HSItoRGB(), and RGBtoHSI().


Function Documentation

template<class T >
void HSItoRGB ( T *  HSI,
T *  RGB 
)

Definition at line 429 of file picimage.cpp.

References PIC_IMAGE_PI.

                              {
  T H = (T)HSI[0],
    S = (T)HSI[1],
    I = (T)HSI[2],
    a = I*(1-S),
    R = 0, G = 0, B = 0;
  if (H<120) {
    B = a;
    R = (T)(I*(1+S*std::cos(H*PIC_IMAGE_PI/180)/std::cos((60-H)*PIC_IMAGE_PI/180)));
    G = 3*I-(R+B);
  } else if (H<240) {
    H-=120;
    R = a;
    G = (T)(I*(1+S*std::cos(H*PIC_IMAGE_PI/180)/std::cos((60-H)*PIC_IMAGE_PI/180)));
    B = 3*I-(R+G);
  } else {
    H-=240;
    G = a;
    B = (T)(I*(1+S*std::cos(H*PIC_IMAGE_PI/180)/std::cos((60-H)*PIC_IMAGE_PI/180)));
    R = 3*I-(G+B);
  }
  R*=255; G*=255; B*=255;
  RGB[0] = (T)(R<0?0:(R>255?255:R));
  RGB[1] = (T)(G<0?0:(G>255?255:G));
  RGB[2] = (T)(B<0?0:(B>255?255:B));
}
template<class T >
void RGBtoHSI ( T *  RGB,
T *  HSI 
)

Definition at line 408 of file picimage.cpp.

References PIC_IMAGE_PI, QuadProgPP::pow(), QuadProgPP::sqrt(), and QuadProgPP::sum().

                              {
  T R = RGB[0],
    G = RGB[1],
    B = RGB[2],
    nR = (R<0?0:(R>255?255:R))/255,
    nG = (G<0?0:(G>255?255:G))/255,
    nB = (B<0?0:(B>255?255:B))/255,
    m = nR<nG?(nR<nB?nR:nB):(nG<nB?nG:nB),
    theta = (T)(std::acos(0.5f*((nR-nG)+(nR-nB))/std::sqrt(std::pow(nR-nG,2)+(nR-nB)*(nG-nB)))*180/PIC_IMAGE_PI),
    sum = nR + nG + nB;
  T H = 0, S = 0, I = 0;
  if (theta>0) H = (nB<=nG)?theta:360-theta;
  if (sum>0) S = 1 - 3/sum*m;
  I = sum/3;
  HSI[0] = (T)H;
  HSI[1] = (T)S;
  HSI[2] = (T)I;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines