tommybazar / TBRaymarchProject

Allows volumetric rendering of 3D data with Unreal Engine.
MIT License
151 stars 40 forks source link

Mhd import fail: Failed to create asset #1

Closed nicolaskopp closed 3 years ago

nicolaskopp commented 3 years ago

First of all, thank you very much for this plugin and the repo! I've been playing around with it all day, saw the tutorial on youtube and wanted to give it a try with some testfiles.

I opened your existing project, recompiled it. Not using the plugin in my own project, yet.

For testing some other content than your demo content (MHD_70), I loaded some dicom sample files and converted them to mhd using ImageJ, specifically this build: https://imagej.net/Fiji

I used "open image sequence" and then selected the a dicom file, and then "save as.." and selected mhd.

Here are the dicom sample files I used:

https://www.visus.com/fileadmin/content/pictures/Downloads/JiveX_DICOME_Viewer/democases.zip

I can re-open the generated mhd in imageJ just fine, but when I try to drag & drop the mhd file into my content browser with your project open, I get:

Failed to import 'case2.mhd'. Failed to create asset '/Game/DefaultResources/case2'. Please see Output Log for details.

Output log, however, is empty. I am also not able to load mhd files with your provided In-Game-GUI, when I click load normalized or Load F32, and select a mhd file, just nothing happens.

I can only guess imageJ converts the dicom files to some form of mhd, which this plugin does not like and cannot parse. I don't know what goes wrong, though, because as said, the Output Log does not show any additional errors.

Any advice is highly appreciated. Thanks!

tommybazar commented 3 years ago

Thanks for the heads-up, I'll check it out tomorrow when I get to my workstation. Honestly, the MHD parser isn't very robust, so it's probably some MHD tag I ignore and it's important.

If you could upload the generated .mhd header for me, that would be jolly good.

nicolaskopp commented 3 years ago

wow, that was quick!

Sure thing, please find the demo mhd attached as a zip (mhd + raw inside zip). democases.zip

let me know if you need anything else, screenshare, coffee, beer, etc.

tommybazar commented 3 years ago

Open the .mhd in notepad and try replacing "ElementSize" with "ElementSpacing" and see what happens.

nicolaskopp commented 3 years ago

Thanks for the head-up. That works - kind of. It now loads, both via drag & drop and also with the GUI, but the file itself seems to be all messedd-up and not readable / useful, as everything is just plain black.

image

so it is definitely a problem with the "wrong" mhd file format, we just have to figure out how to provide useful and "good" mhd files for the plugin to be processed.

Edit: If I dont's choose "Normalize" on import, the file looks like this:

image

tommybazar commented 3 years ago

Aight, will take a look at it tomorrow after work :) My first guess would be little/big endian issue, since I just flat-out ignore that MHD tag in my reader 😁

nicolaskopp commented 3 years ago

Awesome! Thank you so much for looking into this!

if it helps, here is some info on the mhd file used:

(Fiji Is Just) ImageJ 2.1.0/1.53c; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 79MB of 12153MB (<1%)

Title: case1.raw Width: 512 pixels Height: 512 pixels Depth: 31 pixels Size: 31MB Voxel size: 1x1x1 pixel^3 ID: -3 Bits per pixel: 32 (float) Display range: 0 - 2600.7402 Image: 1/31 No threshold ScaleToFit: false Uncalibrated Path: C:\Users\Nico\Downloads\democases\case1.raw Screen location: 534,220 (1646x1029) Coordinate origin: 0,0,0 No properties No overlay No selection

you can open and analyze the file with imageJ.

i will try to create a different mhd format or save to RAW and see where that takes me in the meantime.

nicolaskopp commented 3 years ago

Just as an update, I made some progress and I am sometimes at least able to open some mhd files. In essence, the mhd loader seems to be quite squeamish on what you throw at it. The window and width sliders actually don't work with any file that I tried.

I am not quite sure what to file as a bug here, but I guess the bottomline is, that the mhd loader needs a lot of real-world testing with different files from different sources.

What I did was to google dicom sample files from various places, with this as a starting point:

https://talk.openmrs.org/t/sources-for-sample-dicom-images/6019

I then converted the dcom files with Fiji ( https://imagej.net/Fiji ):

Import -> Image Sequence ->

then

save as... -> mhd. Be sure to manually add "mhd" to the filename as a file extension, then imageJ will create the .mhd header file and .raw file for you! You can also open these files in imageJ just fine and it will then show a slider to "march" through the image layers.

To be able to open these files in your plugin, I have been replacing "ElementSize" with "ElementSpacing" in the .mhd header file like you said, and when I then try to throw it at Unreal Engine Content Editor, the results vary from:

Hope this helps you and everyone else who is reading this in the future as a starting point.

I can provide you with some dicom and also converted mhd files to play around with but basically it boils down to the fact that some do open, some do not, and I was definitely completely out of luck on doing any width or window adjustments on the files that DO work, as it crashes the plugin almost instantly and ranges of the sliders are crazy high / low / nonsenical.

Let me know if you need additional input or files to play around and/or test with!

tommybazar commented 3 years ago

Heya again, finally got around to taking a look at this. I did find a bug in the MHD factory where I wasn't properly setting up the bNormalized flag, which resulted in the sliders screwing up.

Also found and fixed a bug that I didn't label a member UPROPERTY, so it got garbage collected and caused a crash when loading a new MHD file.

Other than that, I tried importing like 3 different dicom files converted to MHD through Fiji and all of them worked fine, pls share with me the ones that don't work and I'll take a look.

I'm not gonna spend too much time fixing the MHD reader though, as the real solution to this is a proper DICOM reader using some 3rd party library, I'll work in the coming weeks to abstract away the MHD-related stuff and make the volumes more generic (not specifically MHD or DICOM).

nicolaskopp commented 3 years ago

Thank you so much! I will take a look at your changes, make some tests and also make sure that you can get a hold of any mhd files which then still might not be working.

I agree that the mhd loader is not a final solution but a step in between, and that something like a wrapper for pydicom would be the way to go, although Unreal Engine can be really trricky when it comes to wrappers and third party libraries.

I'll keep you posted!

nicolaskopp commented 3 years ago

Sorry for the delay. The import works fine now and I had no more issues thus far. Great job! issue can be closed :-)

greenwoodms06 commented 3 years ago

@nicolaskopp From this discussion it was unclear what the necessary steps were to create a mhd file that was readable by this plugin. Could you elaborate?

For example, your democase still provides the same strange red imagery as before. Any tips would be great as I am having the same difficulties importing mhd files. Thanks.

tommybazar commented 3 years ago

The "strange red imagery" is to be expected when importing without normalization.

Do the volumes look corrupted in the viewport? Upload me the files and I can try.

greenwoodms06 commented 3 years ago

When I attempt to bring in the .mhd file I created (using ParaView), the created volume texture is just black if I select "No" on the mhd import prompt regarding G8/G16. If I select "Yes" UE crashes.

Here is the current file I'm using to test. It loads into Slicer just fine it seems.

https://www.dropbox.com/s/yzw7miksz89up4p/test.zip?dl=0

tommybazar commented 3 years ago

The generated .mhd file is compressed, I have no idea how to handle that. Try creating it uncompressed somehow.

tommybazar commented 3 years ago

So, I hacked in support for compressed .mhd files, but your file being black is not a huge surprise - the values are extremely close to zero. The windowing parameters need to be very, very close to zero to see anything.

Try importing it now and setting these settings in the generated MHDAsset.

image

tommybazar commented 3 years ago

What data is that? Looks wonky :) And this TF + Windowing params look good with it :)

image

greenwoodms06 commented 3 years ago

Excellent! Thanks a bunch. Looks like I definitely need to do some pre-scaling on the data, but that isn't a problem. Thank you very much for working your magic. Haha, yea... the data isn't biomedical imagery. Playing around in some other fields :) Again, thank you thank you thank you.