Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw input preview #356

Closed
wants to merge 37 commits into from
Closed

Conversation

paskino
Copy link
Collaborator

@paskino paskino commented Jul 17, 2023

Should close #383

This PR did not pass the tests. Part of the work has been used in a new PR #410.

  • Adds preview button to the raw input dialog.

  • hides slider in the preview dialog (see hide option for slider #384)

  • hides one of the axes in 2D viewer preview (merged hide axis when creating viewer 2D #408)

  • Tested on knee data and not working. A working version has been found in another branch after removing the fortran ordering. (@paskino)

  • add unit tests (or not?)

  • run unit tests. At the moment many are failing (@paskino)

Not to be done in this PR:

@paskino paskino marked this pull request as ready for review July 29, 2023 02:33
@paskino paskino changed the base branch from raw_input_preview to master July 31, 2023 08:17
Copy link
Member

@lauramurgatroyd lauramurgatroyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked great with the 16bit dataset that I tried, but I had problems with an 8bit dataset...
The preview cut the slice in half:
image

But when pressing 'OK' with those same settings, it loaded fine:
image

Wrappers/Python/ccpi/viewer/ui/dialogs.py Outdated Show resolved Hide resolved
Wrappers/Python/ccpi/viewer/ui/dialogs.py Outdated Show resolved Hide resolved
Wrappers/Python/ccpi/viewer/ui/dialogs.py Outdated Show resolved Hide resolved
Wrappers/Python/ccpi/viewer/ui/dialogs.py Outdated Show resolved Hide resolved
Wrappers/Python/ccpi/viewer/ui/dialogs.py Show resolved Hide resolved
Wrappers/Python/ccpi/viewer/ui/dialogs.py Outdated Show resolved Hide resolved
Wrappers/Python/ccpi/viewer/ui/dialogs.py Outdated Show resolved Hide resolved
Comment on lines 239 to 271
if dimensionality == 3:
# read the centre slice
slice_size = shape[1]*shape[0]
offset = shape[2]*slice_size//2

rawfname = os.path.join(tempfile.gettempdir(),"test.raw")

offset = offset * bytes_per_element
slices_to_read = 1
if shape[2] > 1:
slices_to_read = 2
with open(self.fname, 'br') as f:
f.seek(offset)
raw_data = f.read(slice_size*bytes_per_element* slices_to_read)
with open(rawfname, 'wb') as f2:
f2.write(raw_data)

reader2 = vtk.vtkImageReader2()
reader2.SetFileName(rawfname)

vtktype = Converter.dtype_name_to_vtkType[dt.name]
reader2.SetDataScalarType(vtktype)

if isBigEndian:
reader2.SetDataByteOrderToBigEndian()
else:
reader2.SetDataByteOrderToLittleEndian()

reader2.SetFileDimensionality(len(shape))
vtkshape = shape[:]
if not isFortran:
# need to reverse the shape (again)
vtkshape = shape[::-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using the RawCroppedReader here instead, to avoid repetition of code

Copy link
Collaborator Author

@paskino paskino Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the cilRawCroppedReader but it gave the wrong output, which means that selecting from the dialog Fortran or C-order would preview a correct but different slice. In this case the preview would not be useful and the user might select open with the wrong setting.

This did not happen with the above code.

I updated cilRawCroppedReader with the code above. I haven't done more testing of this except using cilviewer to load a raw file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paskino is this conversation resolved or should we do more tests?

Co-authored-by: Laura Murgatroyd <[email protected]>
@paskino
Copy link
Collaborator Author

paskino commented Sep 14, 2023

This worked great with the 16bit dataset that I tried, but I had problems with an 8bit dataset... The preview cut the slice in half: image

But when pressing 'OK' with those same settings, it loaded fine: image

Could you share the dataset?

central_slice = 'z'
else:
shape = (dimZ, dimY, dimX)
central_slice = 'x'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added
if dimensionality == 3: if isFortran: shape = (dimX, dimY, dimZ) central_slice = 'z' else: shape = (dimZ, dimY, dimX) central_slice = 'x'

This means that the axes in the preview are wrong. We need to rotate them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test the code for dimensionality = 2, I need data for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now added to the preview.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that we should also swap the axis labels when loading the whole image. This would be done in the application that uses the viewer, not in this dialog.

@paskino paskino force-pushed the raw_input_preview branch from 7418344 to c210597 Compare April 15, 2024 23:07
@DanicaSTFC DanicaSTFC linked an issue Apr 25, 2024 that may be closed by this pull request
@DanicaSTFC
Copy link
Collaborator

DanicaSTFC commented Apr 30, 2024

This worked great with the 16bit dataset that I tried, but I had problems with an 8bit dataset... The preview cut the slice in half: image
But when pressing 'OK' with those same settings, it loaded fine: image

Could you share the dataset?

Data has been shared in Tomography-Data, DVC

The "file 40891_8bit_1431-1260-1335" is not uploaded correctly with the settings indicated by @lauramurgatroyd

By editing the fortran ordering the image is uploaded correctly, this work is currently stored in another branch

@DanicaSTFC DanicaSTFC added this to the Version 24.0.0 milestone May 2, 2024
@paskino
Copy link
Collaborator Author

paskino commented May 15, 2024

Probably we should rename Size XYZ to height width and number of images as done in ImageJ
This would render the Fortran thing useless.

@DanicaSTFC
Copy link
Collaborator

Probably we should rename Size XYZ to height width and number of images as done in ImageJ This would render the Fortran thing useless.

If we do so we should add an option in the app where the user can rename the labels eg. when saving images for research papers and investigating their system

@paskino
Copy link
Collaborator Author

paskino commented May 15, 2024

If we do so we should add an option in the app where the user can rename the labels eg. when saving images for research papers and investigating their system

Yes, but that would be and advanced feature. So far I'd be happy if the dialog required the appropriate information and used it well. The axis labels defaults could, on first instance, remain X,Y and Z.

@paskino
Copy link
Collaborator Author

paskino commented May 15, 2024

The probable culprit of the failing unit tests is the change in the conversion.py

@DanicaSTFC
Copy link
Collaborator

DanicaSTFC commented May 17, 2024

If we do so we should add an option in the app where the user can rename the labels eg. when saving images for research papers and investigating their system

Yes, but that would be and advanced feature. So far I'd be happy if the dialog required the appropriate information and used it well. The axis labels defaults could, on first instance, remain X,Y and Z.

I opened a new issue for this #406. The topic should be addressed in #390 as we will not address this here. I opened a new issue #407 for the advanced feature

@DanicaSTFC
Copy link
Collaborator

Closed as superseded by #410

@DanicaSTFC DanicaSTFC closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Raw input preview
4 participants