vtkResliceImageViewer display incorrect (too dark) dicom image - c++

I am using vtkResliceImageViewer vtk library class to display DICOM files. Images are too dark. I don't know if I use it wrong way or it's a bug (there was similar unresolved problem posted before: Correct display of DICOM images ITK-VTK (images too dark)).
I am using custom DICOM data reader and I'm sure data is ok. vtkImageViewer2 class displays it correctly. I'am sure that this is not issue connected to Modality LUT, Rescale Slope/Intercept, VOI LUT and window center/width (values are fine).
I attach basic code example producing two images. Window center = 40 and width = 400 are hardcoded and are 100% proper for tested image. Render window with red background displays image using vtkImageViewer2 class and it's perfectly fine. Render window with green background display image using vtkResliceImageViewer and it's too dark. When I set WindowLevel to -40 instead of 40 it's look close to the proper displayed image.
Both clases use vtkImageMapToWindowLevelColors to apply window transformation. I've tried using SetOutputFormatToLuminance() and PassAlphaToOutputOff() methods of that class but this didn't help.
Does somebody have same problem and resolved it some way?
SeriesDataReader dataReader;
vtkSmartPointer<vtkImageData> data = dataReader.ReadSeriesData();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(900, 900);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(0, 1, 0);
renderer->ResetCamera();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindow> renderWindow2 = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow2->SetSize(900, 900);
vtkSmartPointer<vtkRenderer> renderer2 = vtkSmartPointer<vtkRenderer>::New();
renderer2->SetBackground(1, 0, 0);
renderer2->ResetCamera();
renderWindow2->AddRenderer(renderer2);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor2 = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor2->SetRenderWindow(renderWindow2);
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputData(data);
imageViewer->SetColorLevel(40.0);
imageViewer->SetColorWindow(400.0);
imageViewer->SetupInteractor(renderWindowInteractor2);
imageViewer->SetRenderWindow(renderWindow2);
imageViewer->SetRenderer(renderer2);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkResliceImageViewer> resliceImageViewer = vtkSmartPointer<vtkResliceImageViewer>::New();
resliceImageViewer->SetupInteractor(renderWindowInteractor);
resliceImageViewer->SetRenderWindow(renderWindow);
resliceImageViewer->SetSliceOrientationToXY();
resliceImageViewer->SetRenderer(renderer);
resliceImageViewer->SetInputData(data);
resliceImageViewer->SetSliceOrientation(2);
resliceImageViewer->SetResliceModeToAxisAligned();
resliceImageViewer->SetColorLevel(40.0);
resliceImageViewer->SetColorWindow(400.0);
resliceImageViewer->SetResliceMode(0);
resliceImageViewer->GetRenderer()->ResetCamera();
resliceImageViewer->Render();
imageViewer->GetRenderWindow()->Render();
renderWindowInteractor2->Initialize();
imageViewer->GetRenderWindow()->Render();
renderWindowInteractor2->Start();
resliceImageViewer->GetRenderWindow()->Render();
renderWindowInteractor->Initialize();
resliceImageViewer->GetRenderWindow()->Render();
renderWindowInteractor->Start();

I solved that issue. For proper display of images with wl/ww transformation comment out or remove line 327 in void vtkResliceImageViewer::InstallPipeline() function.
Line 327: this->WindowLevel->SetLookupTable(this->GetLookupTable());

Related

vips thumbnail transparent issue for svg image

I have one transparent SVG image, I am trying to generate the thumbnail of that image. It generates a thumbnail of the image properly, but it removes the transparency of the image and adds a black background to the image. I want to generate thumbnail without losing the transparency of the image.
Note - The same problem with jpg and jpeg images also, but I added white background to the image in svg case it's not make the transparent background
I am using PHP vips library.
Here is my code for that
$im = Vips\Image::thumbnail($filename, 180, ['height' => 225, 'size' => 'both']);
$alpha = $im->hasAlpha();
if($alpha) {
$im = $im->flatten(['background' => [255, 255, 255]]);
}
Just write to a format that supports transparency, like PNG.
For example:
$im = Vips\Image::thumbnail("x.svg", 180, ['height' => 225, 'size' => 'both']);
$im->WriteToFile("x.png");
WEBP, GIF, HEIC, AVIF, TIFF etc. also support transparency. JPEG does not.

How to create transparent Mat

Am trying to create transparent mat but am getting black background image in return so any idea how to do it as i have to overlay this image with some content on camera video feed.
code i tried.
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
imshow( "transparent", comp ); // show black background image.
thanks to #HansHire and #Scheff we find out that problem is in cv::imshow() it not render transparency so to check Mat for transparency it need to dumped to disk to be checked using system image viewer which render transparency very well
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
// imshow( "transparent", comp ); // show black background image because it cant render transparency .
imwrite( "C:/opencv_dump.png", comp ); // transparent upon opening , thumbnail may look black.

Issue with shadows/Opacity on sprites in cocos2d (.png format)

I'm having trouble understanding why sprites with shadows (%opacity layer) looks different in ps and on screen. Here is the comparison:
This is simply because of image formate you set. I guess you set RGBA4444 in code or while exporting spriteSheet. Also remove checkmark Premultiply alpha in texture packer.
Also check in AppDelegate Class:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 //Guru - replaced kEAGLColorFormatRGB565 with kEAGLColorFormatRGBA8
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

Blending with Direct3D SpriteBatch

I'm trying to achieve a simple effect: drawing an image on the screen with a transparent background. I'm using SpriteBatches to do this.
Here is my code for creating the blend state:
D3D11_BLEND_DESC descBlend;
ZeroMemory(&descBlend, sizeof(descBlend));
descBlend.RenderTarget[0].BlendEnable = true;
descBlend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
descBlend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
descBlend.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
descBlend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
descBlend.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
descBlend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
m_d3dDevice->CreateBlendState(&descBlend, &m_Blend);
I begin drawing my sprites with:
m_SpriteBatch->Begin(SpriteSortMode_BackToFront, m_Blend);
Nothing shows up on the screen! Am I missing something?
I'm sure my image is correct because when I draw with no blending enabled, everything shows up except the transparent parts become pure white.
Any help would be appreciated.
I was once trying to achieve something similar and wrote down what I did over at gamedev
You have to identify which components of each pixel of a render target are writable during blending.
descBlend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
With ZeroMemory(&descBlend, sizeof(descBlend)); your clear all fields of the D3D11_BLEND_DESC inclusive the RenderTargetWriteMask. This mask determines whether the channels are written or not, if it's zero nothing is written. Try to set it to D3D11_COLOR_WRITE_ENABLE_ALL.

How to change the background colour of a wxTextCtrl without breaking the inactive selection colour?

I want to signal an input error in a wxGTK application by setting the background of a text field to red on error and to white on successful input. However, when the background color is set via SetBackgroundColor, the background colour of an inactive selection is set to the same color. This leads to a very undesirable situation when setting the background colour to white: Since the foreground color for selected text is white, and the background colour for selected text is now also white, the text is unreadable.
How can I reset the colours on a wxTextCtrl so that inactive selected text has a grey background (the default setting before SetBackgroundColour)? SetBackgroundStyle( wxBG_STYLE_SYSTEM) was my first guess, but has no effect on wxGTK.
Code example:
#include <wx/textctrl.h>
#include <wx/frame.h>
#include <wx/defs.h>
#include <wx/app.h>
class App : public wxApp {
bool OnInit() {
wxFrame* frame = new wxFrame(NULL, wxID_ANY, wxT("Frame"));
wxTextCtrl* text = new wxTextCtrl( frame, wxID_ANY, wxT("foo bar") );
text->SetBackgroundStyle( wxBG_STYLE_COLOUR );
text->SetBackgroundColour( *wxWHITE );
frame->Show();
return true;
}
};
IMPLEMENT_APP( App );
You could try working with SetDefaultStyle, I didn't try this myself but here is some excerpt from the wxwidgets documentation:
text->SetDefaultStyle(wxTextAttr(*wxRED));
text->AppendText("Red text\n");
text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
text->AppendText("Red on grey text\n");
text->SetDefaultStyle(wxTextAttr(*wxBLUE);
text->AppendText("Blue on grey text\n");
This will most likely allow you to change the colour independantly of the text and/or change the colour of the text itself as well. Here is the link to the wxTextCtrl Documentation where I found this code snippet:
http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html
Regards,
Roin
Tried this and it works:
TextCtrl1->SetBackgroundColour(wxColour(0xFF,0xA0,0xA0));
TextCtrl1->SetStyle(0, -1, TextCtrl1->GetDefaultStyle());