void displayData(const ComplexVector<T> &data, ImageSize size, const QString& title) { std::vector<T> dataValue; int n0 = size.x; int n1 = size.y; int n2 = size.z; if (n2 < 2) n2 = 2; int nImages = 4; int start = (n0 * n1) * (n2 / 2 - 3); int end = (n0 * n1) * (n2 / 2 - 3 + nImages); for (auto it = data.begin() + start; it < data.begin() + end; it++) { float value = std::abs(*it); dataValue.push_back(value); } float max = *std::max_element(dataValue.begin(), dataValue.end()); float min = *std::min_element(dataValue.begin(), dataValue.end()); QImage dataImage(n1 * nImages, n0, QImage::Format_Indexed8); for (int i = 0; i < 256; i++) { dataImage.setColor(i, qRgb(i, i, i)); } int i = 0; for (int y = 0; y < n0; y++) { auto imageLine = dataImage.scanLine(y); i = y * n1; for (int j = 0; j < nImages; j++) { for (int x = j * n0; x < j * n0 + n1; x++) { Q_ASSERT(i < dataValue.size()); uint idx; if (max == min) idx = 127; else idx = (dataValue[i] - min) / (max - min) * 255; imageLine[x] = idx; i++; } i += n0 * (n1 - 1); } } QPixmap pixmap = QPixmap::fromImage(dataImage); QLabel *imgWnd = new QLabel("Image Window"); imgWnd->setWindowTitle(title); imgWnd->setPixmap(pixmap); imgWnd->show(); }
void ImageFilter<T>::crop(const ImageSize &imageSize) { auto size = m_associatedData.imageSize(); auto x0 = (size.x - imageSize.x) / 2; auto y0 = (size.y - imageSize.y) / 2; auto z0 = (size.z - imageSize.z) / 2; if (x0 < 0 || y0 < 0 || z0 < 0) { std::cerr << "Crop size larger than image" << std::endl; return; } ComplexVector<T> out; ImageData<T> img(m_associatedData.dim(), imageSize); for (int n = 0; n < m_associatedData.channels(); n++) { out.resize(imageSize.x * imageSize.y * imageSize.z); auto itOut = out.begin(); auto itInput = m_associatedData.getChannelImage(n)->cbegin(); for (auto z = 0ul; z < imageSize.z; z++) { auto in1 = (z + z0) * (size.x * size.y) + y0 * size.x; for (auto y = 0ul; y < imageSize.y; y++) { auto in2 = y * size.x + in1 + x0; for (auto x = 0ul; x < imageSize.x; x++) { auto in3 = x + in2; *(itOut++) = *(itInput + in3); } } } img.addChannelImage(std::move(out)); } m_associatedData = std::move(img); }