ValueError: Stage response to 'p?'

Now the fieldwork is over, adding the lessons learned from that into stitching is a priority (hopefully with a paper coming soon). For now @bazzo, could you please run it with

--thresholding_method manual

and when prompts appear for the x and y limits, set 0.9998 and 150 respectively?

In case you’re interested, at the moment the threshold for “good” stitching between two images is automatic - it removes the worst pairs of images until it’s happy. However, it will only remove pairs while there’s still a direct connection between all images ie, it’ll refuse to accept that some images have no good pairs. Using manual thresholding lets you overrule that: you can force images with only bad correlations to be placed according to the stage, but the well correlated images still get stitched properly

TLDR: stitching works by pairing up overlapping images. Automatic stitching sometimes keeps too many of these pairs, manual stitching to only select the bottom right corner of the “peak quality” graph can help

1 Like

@WilliamW: Yes the stitching algorithm had to do some guesswork, especially with the pictures without any sample. The bottom row issue in the last stitched image is caused by the backlash that is ignored when scanning: It’s the only place in the raster where the direction of the cogs is reversed. Similarly you can see in the 5th post of this thread, that when I used “snake” the entire columns were shifted.
@JohemianKnapsody: I see. The few, manualy chosen, “peak quality” stitches are then probably the 12 from the bottom row. The ones which suffered from the backlash-issue. I’ll try it next week. I planned to just start a row below the samples to avoid this issue and only use the stiched_from_stage.jpg. When I crash the script and get the ˋIndexErrorˋ, it speeds up the calculation as well :wink: . In the future, I might try to take a few z-slices and focus-stack several stiched images using the application from Petteri Aimonen.

Thank you again for all your work and help. Even though I’m only “stealing” your software. I’m very happy with the outcome so far.

1 Like

Stitching works well with --thresholding_method manual

Focus stacking is not yet there. The computer struggles with the large stitched images. And when I focus stack the tiles first, their image size is changed and I loose the exif information. As @JohemianKnapsody said: it would be nice to integrate it in the long term…

2 Likes

Even though I’m only “stealing” your software. I’m very happy with the outcome so far.

Testing out our software and telling me what it needs is really useful!

The computer struggles with the large stitched images

At the moment, we run in two ways - using as much memory as it wants, or using the minimum amount possible (around 0.6GB) which is obviously a lot slower. What I can look into is automatically using a maximum of ~90% of the available memory, so it’s as fast as possible without crashing. Leave that with me…

when I focus stack the tiles first, their image size is changed and I loose the exif information

If we can figure out how to keep the camera stage mapping info, we can crop all the images after stacking to be the same size and then it should work

If you think that any of these would be useful for me to work on sooner rather than later, do let us know

1 Like

Focus stacking would indeed be very welcome. It is faster than autofocus and can capture more information.

Speaking of bugs in the software: There’s a small inconvenience with the file numbering from the scanner. There are only two leading zeros when taking more than 1000 pictures (001.jpeg instead of 0001.jpeg).

Sorry. There’s a misunderstanding. Not the openflexure-stitch app is struggling. The focus-stacker (ImageJ or Petteri) doesn’t manage to stack the 3 stitched images, each ~50mb.

I wrote a bash script to stack the tiles at each xy position first and a R script to copy the exif data. That’s where the camera stage mapping info is kept, right? However, when stitching I then get an error from which I guess the exif is corrupted. Maybe I should have learned Python :thinking:.
Also the focus stacker decreases the size by a few px. When I crop all images to 800x600 before stitching, I still get the same error.

$ openflexure-stitch ./stacked/.
Traceback (most recent call last):
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/loading/metadata.py", line 36, in read_metadata_from_file
    usercomment = exif_usercomment_json(exif)
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/loading/metadata.py", line 128, in exif_usercomment_json
    return json.loads(exif_dict["Exif"][piexif.ExifIFD.UserComment].decode())
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bazzo/.local/bin/openflexure-stitch", line 8, in <module>
    sys.exit(load_tile_and_stitch_cli())
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/pipeline.py", line 112, in load_tile_and_stitch_cli
    load_tile_and_stitch(
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/pipeline.py", line 34, in load_tile_and_stitch
    tiling_inputs, starting_csm, csm_calibration_width = load_images(
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/loading/__init__.py", line 23, in load_images
    image_metadata = load_metadata_for_images(folder, fnames, tiling_settings)
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/loading/__init__.py", line 71, in load_metadata_for_images
    metadata_list: List[ImageMetadata] = [
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/loading/__init__.py", line 72, in <listcomp>
    read_metadata_from_file(
  File "/home/bazzo/Downloads/openflexure-stitching/src/openflexure_stitching/loading/metadata.py", line 82, in read_metadata_from_file
    stage_position = [int(d) for d in m.groups()]
AttributeError: 'NoneType' object has no attribute 'groups'

Focus stacking would indeed be very welcome. It is faster than autofocus and can capture more information.

I was afraid you’d say focus stacking! It’s the thing I’ve looked at the least, but I can add it to the list

Speaking of bugs in the software: There’s a small inconvenience with the file numbering from the scanner. There are only two leading zeros when taking more than 1000 pictures (001.jpeg instead of 0001.jpeg).

I think you’re taking the record for most images taken on an OFM in a single scan! I’ll look at the best way to fix that

Also the focus stacker decreases the size by a few px. When I crop all images to 800x600 before stitching, I still get the same error.

It looks like there’s an issue with your exif data, but as a back up it tries to read the location from the image name - if you save them in a format like ./name_{x_coordinate}_{y_coordinate}_{z_coordinate}.jpg, it should be able to get past that error (but no guarantee what error you’d run into next!)

If you could send me a small (maybe 4x4x5 scan) then I’d be happy to take a look

The openflexure-stitch tool was not able to stitch with just the information of the file names.
I wrote a bash-script which does the focus stacking of the individual tiles and copies the exif data. The openflexure-stitch tool is then able to stitch the images together.

It requires two programs: exiftool and focus-stack

#!/bin/bash

fileList=(./*.jpeg) # get all images in folder
# echo $fileList

nFiles=$(ls *.jpeg | wc -l)
echo "We have so many Files: "$nFiles

div=$1 # Get the number of focus levels
 
nDir=$(expr $nFiles / $div)  # Calculate the number of folders that will be created
echo "We have so many folders: " $nDir
echo "We have so many focus levels: " $div

a=0  # Create indexing variable

for i in $( seq 1 $nDir)  # Loop that will create folder, put files from a xy coordinates in, focus stacks them and copies the exif data
	do 
		mkdir $i  # create folder
		
		for j in $( seq 1 $div) # Loop to move the files from one xy coordinate
			do
				mv ${fileList[$a]} $i
				echo ${fileList[$a]} moved to $i
				a=$((a+1))
			done
			
		cd $i 
		stackList=(*.jpeg)			
		cd ..
		echo "First file of stack" ${stackList[1]}
		~/focus-stack.AppImage $i/* --output=s_${stackList[1]}  # Focus stacking app. Change the path!
		exiftool -tagsfromfile $i/${stackList[1]} -exif s_${stackList[1]} # copy exif
		
	done
	
	mogrify -gravity center -extent 822x616  s_* # crop the stacked images
#	mogrify -gravity center -extent 832x624  s_*