# Fourier Ptychography with the OpenFlexure Microscope

**URL:** <https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472>\
**Category:** General\
**Created:** [20 June 2026 09:09 UTC](https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472 "2026-06-20T09:09:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lennartg](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lennartg](https://openflexure.discourse.group/u/lennartg)\
**Post date:** [20 June 2026 09:09 UTC](https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472/1 "2026-06-20T09:09:31Z")

</div>

Hi everyone, as a follow-up to [Has anyone successfully done Fourier ptychography using the Delta Stage - #10 by rooksoup](https://openflexure.discourse.group/t/has-anyone-successfully-done-fourier-ptychography-using-the-delta-stage/2253/10) I thought I’d share my approach of doing Fourier Ptychographic Microscopy with the OpenFlexure microscope. It’s all independent spare time low-budget work that I mostly did at CoMakingSpace Heidelberg. Naturally, this means that I did not have ideal conditions for imaging / handling the optical components and that I didn’t have enough time to dig into all the different components that I used. I’d appreciate comments, especially if I adapted the OpenFlexure software correctly into my workflow and where it could be improved.

Following the recommendation by @rooksoup, I changed my LED matrix mount to the one used in OpenFPM ( [GitHub - YoItsLewis/Open-Fourier-Ptychographic-Microscopy: Open Fourier Ptychographic Microscopy (Open FPM) is an open-source, low-cost platform for high-resolution computational microscopy. · GitHub](https://github.com/YoItsLewis/Open-Fourier-Ptychographic-Microscopy) ) with modifications for a commercial XY stage. For the first time now I got good reconstructions from the 9 most central brightfield images. It is very hard to capture any signal under darkfield illumination of just one activated LED with the setup I have, and so I didn’t manage to do FPM with higher illumination angles.

# Hardware

- OpenFlexure microscope v7 beta2, high-resolution microscope
  - LED matrix mount modified from OpenFPM (using FreeCAD) with an adapter to an XY stage from aliexpress
  - Extended optics module to 160mm mechanical tube length and removed the tube lens [Assembly Instructions](https://build.openflexure.org/openflexure-microscope/v7.0.0-beta1/info_pages/imaging_optics_explanation.html) (OpenSCAD)
  - Additional microscope stand to accommodate to the extended optics module (Onshape)
  - Default camera (Raspberry Pi Camera Module v2)

- Pimoroni Unicorn HAT HD
- 4X NA 0.1 objective
- USAF 1951 target

## Modified OpenFlexure Microscope

 ![setup](https://global.discourse-cdn.com/free1/uploads/openflexure/original/2X/e/e0082fd1a46ee34c7d1433af7da82fd2176da8cc.jpeg)

# Software

- I created an extension to the OpenFlexure Microscope Server for LED selection and running FPM acquisition series
  - Image capturing with `use_video_port=False, bayer=True`
  - Pause time between acquisitions to prevent camera freeze
  - Take multiple images per LED position to exceed maximum possible exposure time
  - Take background images with no LED active

- ImageMagick and Fiji for processing the acquired images
- FPMApp for reconstructions [Release FPM app 1.1 · MRogalski96/FPM-app · GitHub](https://github.com/MRogalski96/FPM-app/releases/tag/1.1)
  - I don’t have a matlab license - installed FPMApp with the released installer on windows, then copied over to linux and ran with wine

# Workflow

## 1. Acquisition in the OpenFlexure software

- No calibrations
- Analog gain=1, digital gain=1
- LED centering by comparing the different brightfield/darkfield transition images
- Set exposure time to match LED PWM frequency (don’t get visible horizontal stripes on images)

## 2. Image processing

- Extract channel of interest from Bayer DNG image with rawpy and by pixel subsampling
- Sum projection of images for each LED position
- Background subtraction for summed images of each LED position

## 3. Fourier ptychography reconstruction in FPMApp

- Select ROI, acquisition order, central LED
- Enter parameters of the FPM setup

# Example reconstruction from 9 brightfield images

 ![reconstruction](https://global.discourse-cdn.com/free1/uploads/openflexure/original/2X/9/9b6521ad508ca262c2ccb96ff4759c3712dc6a6b.jpeg)

## FFT of raw image and recovered image

 ![fft_comparison](https://global.discourse-cdn.com/free1/uploads/openflexure/original/2X/1/1b42608e2e54fa28499f84dc7b2a76d9b1303dea.jpeg)

## System parameters in FPMApp

- Position correction with Authors method 2 (fast)
- 50 epochs
- 9 images, all brightfield
- 64mm
- Synthetic NA: 0.24
- 620nm wavelength

# Limitations

- Default v2 camera introduces a lot of background noise
- The selected exposure time probably does not perfectly remove the PWM flicker from the acquired images, a global shutter camera could address this better
- Cannot process darkfield angles, probably due to a too low quality camera or not having an optics room and vibration isolation table

# Remarks / questions

I couldn’t find a definitive source for the following points

- Exposure time in the OpenFlexure GUI. Is it possible to take pictures at the full ~10s exposure time supported by the v2 camera? Apparently it is limited by the camera FPS, but that should only apply to the `use_video_port=True` and not the capture pane. Also, when I set an exposure time, it is always modified to a different value close to the one I entered. It is not clear to me, by what rule.
- With analog gain\>1, sometimes the camera image does not update between acquisitions (automated batch acquisition in a custom extension) and I have to add a few hundred ms pause in between acquisitions. Not sure if this is normal behavior or an issue with the microscope software.

---

<div class="post-metadata">

**Author:** ![WilliamW](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/williamw/32/106_2.png) [@WilliamW](https://openflexure.discourse.group/u/WilliamW)\
**Post date:** [20 June 2026 10:04 UTC](https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472/2 "2026-06-20T10:04:24Z")

</div>

Thank you for sharing @lennartg

---

<div class="post-metadata">

**Author:** ![NickK](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/nickk/32/3136_2.png) [@NickK](https://openflexure.discourse.group/u/NickK)\
**Post date:** [2 September 2026 07:13 UTC](https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472/3 "2026-09-02T07:13:56Z")

</div>

A couple of point on the camera noise. I have a number of cooled CCDs for astronomy I’ve coded for.

a) the HQ camera board has -55dB PSRR power regulators, along with shunts, which should help reduce the powers supply noise to the chip, preamplification and the ADC. I don’t think the V2 has quite the same level of attention to the power supply.

b) Digital isolation can help really drop a large amount of noise. I’m not sure about the V2 (I suspect it simply has inductors to reduce noise) but I do know the HQ has inductors making an LRC filter for noise. What would work better is a digital isolator chip - these break the path and provide Schmitt triggers and completely isolate (magnetic) the digital path and the power supplies to them. Only down side is the isoloators need to work at 2.5Gb/s and you need a multi-path IC chip which will cost £45+ each and you’re likely to need a 4 layer or more PCB.

The image sensor ICs can suffer a number of issues:

- thermal noise - this can be shaped like a heat map of the PCB it’s attached to. So PCB design for removing the heat generating components and allowing cooling is imperative.
- thermal read noise - if you do use Peltier cooled chips, the read noise can cause gradients across the the sensor during read (dependent on the sensor read design). The faster read the more noise occurs, typically the longer exposure astro cameras (20 minute exposures) will switch off the ADC and the preamplifier during the collection phase to reduce thermal and digital noise. Often they do small “flush” of the CCD pixels between images to ensure the CCD pixels are drained fully without going through the conversion process. Dark frame calibration (no light ‘blank’ read) will help detect and allow for compensation but.. this only works if the camera doesn’t attempt to auto-balance or change gain on the preamp stage etc.
- ‘shutter’ artefacts - sensor dependent, some sensors move the image to a quiet location (literally they shift along the row to an area that’s covered). This doesn’t happen immediately and you can get skews, gradients and if pixels are stuck/defective they can cause issues. Some cameras/drivers mask these problems by essentially ‘fudging’ the pixel or line value using the values around it. With bayer matrix colour you will see odd changes/variations of colour, even ‘noise’ appearing as a result. You can use “light frames” (ie calibration frames where there’s uniform light to detect and compensate).
- pixel variations - stuck, partially stuck and dead pixels will create a map that can be removed but if there’s an inbuilt compression (jpeg, video etc) then the resulting image loses that visibility of pixel address and pixel variation. In bayermatrix colour you’ll get a variation of colour that changes.
- power supply and digital noise - enough said already on this. However the analogue circuit is extremely important to get as little noise as possible. However some digital techniques can be used - such as using the clocking designs in the ADC process to effectively blind the process to noise, there’s also noise shaping on the ADC but that’s not something you’ll really be worried about except the chips create high frequency noise.
- clock noise/jitter although you’re not likely to have problems with 1/f noise you will get a variation in ADC with jitter of the read from the chip and the ADC.
- gaussian noise - you’ll get a noise distribution, although you reduce the thermal noise (Jonson-Nyquist thermal noise), you’ll get shot noise etc.

The short of this is - there is an expensive way to isolate which would return a reduction in noise, coupled with low noise power supplies will reduce that noise but thermal and designed tradeoffs of the camera will probably impact more.  
I have created a low noise ADC in the past so I’m familiar with the clocking and isolators but 24Mhz is easier to cope with. 2.4GHz is would be more complex with the PCB track design with board capacitance effects on the impedance return paths (and tracing those problems would require a better scope! Mine’s a Siglent 200Mhz). High frequency noise is more likely to affect the ADC and the clocking of the sensor read than it is the pixels.

A second approach is using software noise reduction using stacked multiple exposures without moving the stage or subject. This uses the stacking to increase the common signal to noise ratio. Thus the image subject signal will increase. The common noise (ie constant pixel, constant shutter or constant conversion noise) will also increase at the same time (as they’re common signal) but the non-constant noise (others mentioned up there) will become spread gaussian noise and thus that noise increases at a slow rate. A complication here is the colour bayer matrix (noise impacts different pixel colours differently) and the averaged pixels use to recreate the missing detail then needs a term in the process for calibration.

Your FFT for the image has some interesting points - specifically noise along the axis of the image rather than the axis of the object. This could imply the noise is not associated with the object itself and could be filtered.

I’ve done this in the astronomy, where I’ve used OpenCL to phase correlate and stack in real time. The same is possible in webgl etc but more research/thinking would be needed on the effect of the bayer matrix. Not impossible but needs additional work. I’ve traditionally used mono cameras (CCD and CMOS sensors with no bayer matrix) and a 2" filter wheel - RGBA in separate channels. Lots of stacking!

The entire process if controlled properly can be done automated - exposure preprocessing, noise reduction stacking, stacking those for super resolution (helps recover image detail between pixels and makes bayer matrix averaging more accurate by giving more data points), and finally stitching.

---

<div class="post-metadata">

**Author:** ![lennartg](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lennartg](https://openflexure.discourse.group/u/lennartg)\
**Post date:** [25 September 2026 08:13 UTC](https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472/4 "2026-09-25T08:13:40Z")

</div>

Thank you very much for your comment, I learned a lot from it!

I would like to clarify my acquisition pipeline with regard to your points.

- I captured images with different active red LEDs in an LED matrix (i.e., different angles)
- I captured RAW images . It’s somewhere on this forum. If I remember correctly, it saves a JPEG with the RAW image in the metadata (EXIF tag).
- From the RAW images, I subsampled the red LED positions (e.g., every other pixel in every other row)
- I found it quite difficult to figure out how I am supposed to control the V2 camera within and outside of the OpenFlexure software. How to disable any automatic gain etc changes, how to achieve the supposed possible max exposure time of 10s etc.
  - I took multiple images per angle, then added them up (sum z projection) for higher exposure time. For how you mentioned I could reduce the noise by stacking, I assume that summing and averaging has the same effect?
  - I took dark frames (same number of frames and acqusition settings and sum z projection) and subtracted them from the different regular acquisitions.

For your proposed light frame calibration I have two concerns:

- A central flaw in my setup is the LED matrix PWM. I could not figure out an exact exposure time for the camera that is guaranteed to fully cancel out the PWM. I choose values for which these horizontal bands were not visible anymore and my exposure times were way higher than one PWM switching period. But due to this I cannot guarantee equal illumination for light frame and regular frames.
- Then, I’m not sure about how to handle the different acquisition angles for light frame calibration. Would I do one light frame with no sample per LED position?

For the noise on the axes of my FFT I assume it’s caused by how I subsampled every other pixel in X and Y direction. It gets augmented in the reconstruction, so I assume that it is important to think about.

I see that I could upgrade to a Raspberry Pi High Quality camera, Global Shutter camera or a third-party compatible monochromatic camera. I don’t know yet which would be the best (WaveShare Mono has a global shutter) but the v2 I used is definitely the worst option.

> [@NickK](#):
>
> The entire process if controlled properly can be done automated - exposure preprocessing, noise reduction stacking, stacking those for super resolution (helps recover image detail between pixels and makes bayer matrix averaging more accurate by giving more data points), and finally stitching.

This is the vision but I am still in a too early stage where the system does not work well. What do you mean by stacking for super resolution (i.e., how to do it in practice?).

Following some papers, I did the reconstructions above on a smaller ROI (like 200×200 pixels). So I would first do stitching on the different reconstructed high resolution ROIs and then I could scan a larger slide and do reconstructions there and combine them.

---

<div class="post-metadata">

**Author:** ![NickK](https://yyz2.discourse-cdn.com/free1/user_avatar/openflexure.discourse.group/nickk/32/3136_2.png) [@NickK](https://openflexure.discourse.group/u/NickK)\
**Post date:** [26 September 2026 05:11 UTC](https://openflexure.discourse.group/t/fourier-ptychography-with-the-openflexure-microscope/2472/5 "2026-09-26T05:11:59Z")

</div>

I’d not considered the use of PWM on the LED. That should average over the PWM pulses. Essentially the sensor pixel itself is a capacitor. The light (irrespective of rate or pulsing) will generate a charge at a rate or pulses until the sensor is read. If we had control over the pulses then we’d have a slightly better match but in this case the sensor isn’t designed for counting photons etc so we need to live with it. There will be differences between the images due to the LED and using post processing to scale.

Ideally you’d want a light frame to model the lens and any variations - that would be any variation caused by different LEDs or their positions. The astrophotographers use a flat field light panel (or DIY a light box todo the same), this creates an average illumination without a point source so you don’t have the issue of LED point sources. You can get microscope flatfield lighting panels but that’s more of a hardware endeavour. The DIY light boxes use a bank of LEDs but use a diffuser so that could be a contribution someone could make but I suspect it’s more difficult due to the magnification.

The issue with diverging from the Openflexure/RP supported cameras is getting access to data sheets for the entire camera and being able to control the various components (ie the ADC etc).  
Once you do, it tends to be a large amount of testing to understand the various impacts of settings and supporting it.

You have an imaging pipeline. Light source → object → lenses → colour matrix → sensor.

1. Get a reference dark frame - you can do this by sampling once, or multiple frames then averaging. This provides a noise pattern of the electronics, the sensor noise and thermal noise.  
This is used to remove noise from every non-dark frame. As it only involves the sensor and no LEDs you should only need one.

2. Get the reference light frame (set) - again you can for each light frame actually take a number of light frames or use a single frame, the light frame is simply the light through the lens, matrix and sensor. It will have all the vignetting for that light position and pixel on the sensor, and the active sensor noise. You could use the dark frame to subtract the light frame sensor noise - this is a bit haphazard but it helps.

3. For each image frame, the light frame and dark frames are used to help correct and remove noise.

4. Using multiple image frames (from 3) then helps increase SNR by additive common signal, whilst the noise then increases at a slower rate. The output is then your image for this stage position.

Use the images for the super resolution.

Note you could simply apply all the image frames into the SR instead of 4.

The main issue with SR imaging is that the images vary in characteristics - the noise floor for example.
