HI All
we are working on an 2D xray porject on VTK and QT and completely stuck at this point
The raw image file from xray detector plate is of 16 bit data. Our work flow is as below
we convert raw data file to Qimage an then Qimage to vtk data to load the image in Vtk renderer.
16 bit Raw data > QImage > VTKData
and after processing in vtk the vtk cast output data is convereted to Qimage first and then to raw data.
the code to create Qimage is
QByteArray array =RAWfile.readAll();
unsigned char* Data = (unsigned char*)&array.data()[0];
QImage myImage(Data,SelectedDetector.ImageWidth,SelectedDetector.ImageHeight,QImage::Format_Grayscale16); //change image size
myImage.invertPixels();
code to create VTK data
vtkNew qimageToImageSource;
qimageToImageSource->SetQImage(&myImage);
qimageToImageSource->Update();
vtkImageData * imgdataEnhance=vtkImageData::New();
imgdataEnhance = qimageToImageSource ->GetOutput();
code for vtk data to Qimage
imagedataSave is output of vtk imagecast in unsigned char scalar
QImage myImage = vtkImageDataToQImage(imgdataSave);
vtkImageDataToQImage(vtkSmartPointer imageData){
ImageWidth = imageData->GetDimensions()[0];
ImageHeight = imageData->GetDimensions()[1];
int dim[3];
imageData->GetDimensions(dim);
QImage m_image( ImageWidth, ImageHeight, QImage::Format_Grayscale16);
QRgb* pixel = reinterpret_cast<QRgb*>(m_image.bits()) + dim[0] * (dim[1] - 1);
for (int x = 0; x <dim[0]; x++)
{
for (int y = 0; y <dim[1]; y++)
{
unsigned char* h = static_cast<unsigned char*>(imageData->GetScalarPointer(x, y, 0));
if(h!=NULL){
QRgb pixel = qRgb(*h, *h, *h);//Because it is processing grayscale images So the three RGB are the same
m_image.setPixel(x, y, pixel);//Each point assignmen
}
}
}
QImage image = m_image.mirrored(false, true);//The obtained image is upside down, use mirror to change the direction.
return image;
}
to covert Qimage to raw data for dicom
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
myImage.save(&buffer, "tiff");
buffer.close();
unsigned char *data = (unsigned char *) malloc(bytes.size());
memcpy(data, reinterpret_cast<unsigned char *>(bytes.data()), bytes.size());
RawDataSize =bytes.size();
RawData = data;
so the issue is when we load the image in VTK the image quality is not good as and when we change window leveling and zooming
seems lke 8 bit data is being used by VTK and this compromise the quality
alternatively when we create a tiff file from the raw data through Qimage and then call that tiff file through vtk image reader, it seems 16 bit image is loaded in vtk , and there is no issue in image quality.
But there is issue to save raw data for dicom the resulting out put image is distorted.
we tried to save the vtk cast output to tiff through tiffwriter, but then the output is 8bit one and image is distorted.
so is there ay way to manage with 16 bit data and retain the image quality in the final saved output raw data a well?
anyway to save vtkoutput to tiff or rawdata directly from vtk renderer? or through qimage in a better way to get the exact vtk output
to load 16 bit raw data directly to vtk and then save directly to 16 bit raw data from vtk?
your help is highly appreciated as we are completely stuck and in dark now
we are even ready to outsource this part on payment basis to someone who are ready to help on this.
Thanks