void Tools::mapHeight() { ImageViewer* iv = getViewer(); if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono << QImage::Format_Indexed8 << QImage::Format_RGB32)) return; MapHeight* mh = new MapHeight(iv->getImage(), iv); mh->start(); }
PNM* MapNormal::transform() { int width = image->width(), height = image->height(); double strength = getParameter("strength").toDouble(); PNM* newImage = new PNM(width, height, image->format()); //qDebug() << Q_FUNC_INFO << "Not implemented yet!"; MapHeight* mh = new MapHeight(image); PNM* imgHeight = mh->transform(); EdgeSobel* es = new EdgeSobel(image); math::matrix<float>* Gx = es->rawHorizontalDetection(); math::matrix<float>* Gy = es->rawVerticalDetection(); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { float dx = (*Gx)(i,j)/255; float dy = (*Gy)(i,j)/255; float dz = 1/strength; double dw = sqrt(dx*dx + dy*dy + dz*dz); dx = dx / dw; dy = dy / dw; dz = dz / dw; dx = (dx + 1.0)*(255/strength); dy = (dy + 1.0)*(255/strength); dz = (dz + 1.0)*(255/strength); QColor newPixel = QColor(dx,dy,dz); newImage->setPixel(i,j, newPixel.rgb()); } return newImage; }
PNM* MapHorizon::transform() { int width = image->width(), height = image->height(); double scale = getParameter("scale").toDouble(); int sun_alpha = getParameter("alpha").toInt(); int dx, dy; switch (getParameter("direction").toInt()) { case NORTH: dx = 0; dy = -1; break; case SOUTH: dx = 0; dy = 1; break; case EAST: dx = 1; dy = 0; break; case WEST: dx = -1; dy = 0; break; default: qWarning() << "Unknown direction!"; dx = 0; dy = -1; } PNM* newImage = new PNM(width, height, QImage::Format_Indexed8); MapHeight* mapHeight = new MapHeight(image); image = mapHeight->transform(); delete mapHeight; for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { double alpha = 0.0; int curr_h = qGray(image->pixel(i, j)); int k = i + dx; int l = j + dy; while(k < width && l < height) { double ray_h = qGray(image->pixel(k,l)); if (curr_h < ray_h) { double dist = sqrt(pow(k - i, 2) + pow(l - j, 2)) * scale; double ray_alpha = atan((ray_h-curr_h)/dist)*180./3.14; if (ray_alpha > alpha) alpha = ray_alpha; } ++k; ++l; } double delta = alpha - sun_alpha; if (delta <= 0) newImage->setPixel(i,j, PIXEL_VAL_MAX); else newImage->setPixel(i,j, cos(delta*3.14/180.)*255); } return newImage; }