sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Creating a RPI-assisted microscope

Tue Apr 10, 2018 12:36 pm

Dear all,

First of all, I hope that my topic is in the right section.

I'm a post-doc in a french university, and I use microscope everyday, I have to take images of microfossils (around 300µm) on a microscope with a camera on it, and assisted with a computer, then upload the images on my computer, and run a small script I wrote on the image software ImageJ (for measuring morphometric parameter), then I export the results on an excel sheet and finally I can plot my results.

My goal is a develop a "automated" image acquisition system, with a raspberry. Why? In order to reduce the number of step, reduce the cost need to acquire all the equipment, and run it on battery so it can be used everywhere. Another interest would be to dedicate SD cards to specific application. If I boot it with another SD card, It could be used for other kind of image acquisition and processing, for example.

The system should be composed of a raspberry, a small screen to check the image, probably a RPI camera, (maybe equiped with a lens), a battery, adjustable mount, light, and a few button (maybe connected with the GPIO?) for the few functions I will need (no mouse or keyboard).

Before starting all of this, and because I'm a beginner in the RPI world, I would like to know, even if not easy, if you think it would be possible to have the system to boot on the specific application, click on one button to create a new take an image (saved on a flash drive for example), click on another button to measure the morphometric parameters of microfossils from the image, then take another image, measure it, and so on... and finally, click on another button to export the results on the flash drive.

Thank you very much for your expertise,

Sonof.

gordon77
Posts: 4253
Joined: Sun Aug 05, 2012 3:12 pm

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 3:34 pm

All sounds feasible.
Can you upload on image to show how you do the measuring?

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 3:58 pm

More than an image, here is a video of almost exactly what I'm doing.

https://www.youtube.com/watch?v=8c68qIz_ftw

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 4:49 pm

Not sure why you need the microscope ;-), see image below. With Raspberry v2 camera (8MP), M12 lens mount, IR 1080P f6.0mm 1/2.7" lens (65°) and two M12 extension rings you can take images with down to 0.77μm/pixel, in a 3280×2464 pixel image:
viewtopic.php?f=43&t=45887&p=1298451#p1298451
In that thread it is described how to attach M12 lens mount as well:

I agree with gordon77 that your project sounds feasible.

Funny, I wrote a program to count the number of particles (0:54 in your video) and compute the area distribution back in 1990. The application scenario was production quality analysis of foam tubes. All cameras were too deep to get a flat image allowing to count and analyze the holes in the foam on flat cut test piece. So we used Kindergarten potato print technique, dipped the to be measured foam piece into printing machine high quality color, used a machine allowing for constant, repeatable pressure for potato print the foam on paper, then scanned the paper print and finally my program did the analysis (it did compute the average outer and inner diameter of the tube as well).

Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 5:25 pm

Hermann: Maybe I didn't explain myself right enough, sorry, I'm not english.

I don't want to use an actual microscope, and add a raspberry on it. I want to do exactly as you did in fact. Use a RPI, a RPI camera V2, add some lenses, to "create" a system that I can use as a microscope.

Can you tell me more about the "M12 lens mount, IR 1080P f6.0mm 1/2.7" lens (65°) and two M12 extension rings " (price, where to buy...)

Do you have other kind of picture of small objects, sand grains... things like this? So I can start to look for some fundings in my lab? The aim is also to propose a "cheap" alternative to "official" scientific equipment which cost a lot.

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 6:23 pm

> Do you have other kind of picture of small objects, sand grains... things like this?
>
I posted all in the thread I pointed to. See below photo that you need to have all interesting stuff in same distance, at least with 65° lens (a roughly 1mm diameter tin solder ball).

> Can you tell me more about the "M12 lens mount, IR 1080P f6.0mm 1/2.7" lens (65°) and two M12 extension rings " (price, where to buy...)
>
These are the parts I bought and tried, all in low single digit $ range:
https://www.aliexpress.com/item/2PCS-Me ... 3842.html
https://www.aliexpress.com/item/CCTV-Le ... 4839.html
https://www.aliexpress.com/item/16mm-Le ... 2070.html
https://www.aliexpress.com/item/M12-Mou ... 4323.html

The less than 1μm/pixel was achieved with the 20° lens.
You can still get 1μm/pixel with (5MP) v1 camera that you can get on aliexpress for 6$ with free shipping.

P.S:
I ordered two more extension rings in order to get even closer to object with lens and see how much below 0.77μm/pixel will be possible.

Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 6:50 pm

Many thanks! Sorry I thought your link was a link to the same image... Very interesting indeed!

What is the purpose of the "IR 1080P f6.0mm 1/2.7" lens (65°)"? Take image of very small item like the ball?

You are using the x20 for "larger" image of specific areas like in the first image?

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 8:38 pm

I'll just add the buttons will connect to the gpio and can trigger scripts or parts of a program,.say in python

You can easily attach the official 7" screen and you will also have a touch screen too.
It's not the cheapest option though if you don't want something that large or touch.

But yes all is plausible.
Have a look at some of the cameras people have made with Pi's.

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Tue Apr 10, 2018 11:29 pm

sonof wrote:
Tue Apr 10, 2018 6:50 pm
What is the purpose of the "IR 1080P f6.0mm 1/2.7" lens (65°)"? Take image of very small item like the ball?
I had no experience with cameras or lenses, so I bought different angle sensors (65°, 20°, 130° and 150°).
My experiments sofar confirmed my assumption that less degree gives better resolution per pixel when used microscope like. I even found and ordered a 3.98° lens and will see whether that is even better.
If you look into the posting where I described how I prepared and then mounted the M12 lens mount you see two photos of bigger (Lego) scene with 130° and 65° lens. So both lenses can be used like a microscope in case of small distance to object, or normal (65° is kind of "zoom" compared to 130° with same distance to object):.
viewtopic.php?f=43&t=45887&p=1298451#p1279957
You are using the x20 for "larger" image of specific areas like in the first image?
Not x20, but 20° lens. With v1 camera 65° lens achieved 1.7μm/pixel, whereas with 20° lens it achieved 1μm/pixel.
I learned that any resolution Xμm/pixel with v1 camera translates to resolution (X/3280*2592)μm/pixel with v2 camera if keeping same distance and lens (it is easy to move lens since I have a v1 and a v2 camera with self added M12 lens mounts).
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Wed Apr 11, 2018 6:42 am

That sounds very promising!

I'll try to order a few things too, probably a 20° and even a lower one, with a few rings.

As our aim to lower the budget as much as possible, does the 8mp camera worth it by comparison to the 5mp?

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Wed Apr 11, 2018 6:57 pm

sonof wrote:
Wed Apr 11, 2018 6:42 am
As our aim to lower the budget as much as possible, does the 8mp camera worth it by comparison to the 5mp?
It is good to have one v2 camera, as it can eg. take VGA videos at 180fps with full GPU support, and it has 8MP compared to 5MP for v1 camera.

On the other hand you get v1 camera for 6$ with free shipping -- I own one v2 camera abd 7 v1 cameras ;-)
[you can get v1 night vision camera for 9$]

Btw, you can take 665fps videos with raspiraw and v1 camera (640x128_s tool) ...

P.S:
From v2 video, "only" 16μm/pixel, but at 180fps (v1 maximal framerate for 640x480 is 95fps).
1cm spark from 800KV igniter, 20° lens, no M12 extension rings:
viewtopic.php?f=43&t=207537&p=1300892#p1300892
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Thu Apr 12, 2018 7:04 am

Cool! I'll probably get both, just in case.

Concerning the Raspberry, do you think a RPI zero can be enough, or it is also better to get a V.3?

thanks.

User avatar
DougieLawson
Posts: 36340
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Creating a RPI-assisted microscope

Thu Apr 12, 2018 7:46 am

sonof wrote:
Thu Apr 12, 2018 7:04 am
Cool! I'll probably get both, just in case.

Concerning the Raspberry, do you think a RPI zero can be enough, or it is also better to get a V.3?

thanks.
If the only thing you're doing is running a camera/microscope then the ZeroW will be more than adequate. Folks have been using original 1Bs (same chip, same amount of RAM (later models)) for that task since the 5MP camera was launched.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Fri Apr 13, 2018 6:54 am

Well, I have to execute ImageJ that should run on Raspbian, so I don't think if a zero is enough... Maybe not?

User avatar
DougieLawson
Posts: 36340
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Creating a RPI-assisted microscope

Fri Apr 13, 2018 7:37 am

sonof wrote:
Fri Apr 13, 2018 6:54 am
Well, I have to execute ImageJ that should run on Raspbian, so I don't think if a zero is enough... Maybe not?
I've downloaded http://wsr.imagej.net/distros/cross-platform/ij150.zip and unzipped it.

I had no problem running that on my old Raspberry Pi 1B (same as a zero) which has the camera attached. Using VNC viewer (because I don't have a monitor attached to it). That raspberry is running things like mosquitto, lirc, lighttpd, postfix.

That worked perfectly.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Creating a RPI-assisted microscope

Fri Apr 13, 2018 9:46 am

How about, if you have the money, buying both and see which you prefer. Remember to get an extra camera 'wire' for whichever the camera doesn't come with as the Pi's end of the connector is different.
You'll then get a feel for use.
That and you can use the Pi3 for development and move across as needed for testing.
That would also give you two comparisons for you research.

Of course the Pi3 comes with downsides, it's larger and will need a larger battery for the same time of use.

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Mon Apr 16, 2018 8:29 am

Thing is, as one of my goal is to make this system as cheap as possible, I cannot ask for too much money to "try several things", even if I would like to, obviously.

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Mon Apr 16, 2018 12:23 pm

Then start with Pi Zero W (10$), v1 night vision camera with M12 lens (10$), Pi Zero camera cable (1$), M12 extension rings (2x2$) and some lenses (few dollars each).
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Creating a RPI-assisted microscope

Mon Apr 16, 2018 1:06 pm

sonof wrote:
Mon Apr 16, 2018 8:29 am
Thing is, as one of my goal is to make this system as cheap as possible, I cannot ask for too much money to "try several things", even if I would like to, obviously.
Sorry my mistake, I thought it was research into being able to make it as cheap as possible. Not to do it as cheap as possible from the start.

(Though the Pi3 is so much easier to actually develop on than the much slower Zero. Only then cut back functions for the Zero as need be for speed and memory).

sonof
Posts: 21
Joined: Tue Apr 10, 2018 12:12 pm

Re: Creating a RPI-assisted microscope

Mon Apr 16, 2018 1:44 pm

HermannSW wrote:
Mon Apr 16, 2018 12:23 pm
Then start with Pi Zero W (10$), v1 night vision camera with M12 lens (10$), Pi Zero camera cable (1$), M12 extension rings (2x2$) and some lenses (few dollars each).
I was exactly thinking about that, I'll try to order it soon. If I don't need wifi or bluetooth, do I need a Pi Zero W, or can I order a v1.3? Do you think I need the night vision option?
bensimmo wrote:
Mon Apr 16, 2018 1:06 pm
sonof wrote:
Mon Apr 16, 2018 8:29 am
Thing is, as one of my goal is to make this system as cheap as possible, I cannot ask for too much money to "try several things", even if I would like to, obviously.
Sorry my mistake, I thought it was research into being able to make it as cheap as possible. Not to do it as cheap as possible from the start.

(Though the Pi3 is so much easier to actually develop on than the much slower Zero. Only then cut back functions for the Zero as need be for speed and memory).
You're also quite right, my goal is to propose a cheap alternative to regular microscope equipment, but for credibility purposes in my lab I cannot afford to try everything. I'll try with the cheapest solution and then buy more expensive stuff if needed. At least, I have a "personal" RPI3 I can use for test.

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Mon Apr 16, 2018 2:24 pm

Yes, Pi 3B or 3B+ are quicker than Pi Zero, but most times single core performance is what is needed, and even that is not an issue for microscope application. See here for a specific lot of integer processing optimized C programm Zero needs 30μs, Pi 2B 27μs, Pi 3B needs 17μs and Pi 3B+ needs 14μs runtime:
viewtopic.php?t=208778#p1291239

If you want as cheap as possible, then yes, Pi Zero (v1.3) is definitely OK instead of Pi ZeroW.
Cheapest connection is USB gadget mode, no ethernet or Wifi dongle needed in that case.
Just a USB cable, I found always these instructions most easy to setup gadget mode, never failed for me:
https://blog.gbaman.info/?p=791

With 5$ for v1.3 Pi Zero you can get all I enumerated before for 5$+ship(Zero)+10$+1$+4$+6$=26$+ship(Zero). Besides the Zero all other parts come with free shipping from aliexpress.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Sat Apr 21, 2018 12:11 am

The 3.98° lens arrived after only 21 days, with 9$ it is much more expensive than the other lenses:
https://www.aliexpress.com/item/HD-2-Me ... 76750.html
Image

Technical data:

Code: Select all

Focal length:70mm 
Mount: M12*P0.5
Image format: 1"
Aperture: F1.6
Optical back length: 0.2mm
Viewing angle: 3.98degree

I was surprised that I had to move the front of lens 63cm distant to Q key on keyboard to get sharp display (I did hold camera in hand). The dots are a sign that I was not careful enough today or before with changing lenses, they show up with different lens as well. Tomorrow I will see whether I can clean the image sensor somehow (sad, this is my only v2 camera, I have 7 v1s):
Image


Next I inserted one M12 extension ring and screwed out extension ring as well as lens maximal. With this setup lense to object distrance needs to be 34.5cm to be sharp:
Image


Finally I added second M12 lens extension ring, here lens to object distance of 27cm was needed for sharp image:
Image


It will take some time before two additional extension rings I ordered 3 weeks ago will have arrived here, and I am not sure whether (only) two more will suffice to get lense very close to object as needed for microscope ...

P.S:
All 3 images are 8MP taken with "raspistill -o test.jpg", right click for details.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Sat Apr 21, 2018 12:24 pm

Nice, today the two ordered M12 extension rings arrived as well, and a Realacc soldering station allowing to hold the now 12cm long Raspberry camera plus 4 extension rings plus 70mm lens and give more stable images than with my hand:
https://twitter.com/HermannSW/status/987661223868198912

Did not clean the v2 camera yet, three M12 extension rings and lens screwed out maximal. With this setup lens to object distance needs to be 21cm to be sharp:
Image


Four M12 extension rings and lens screwed out maximal. With this setup lens to object distance needs to be 17.5cm to be sharp:
Image


Width of '@' is roughly 2.8mm, and in image that is 1800 pixel, so resolution is 1.6μm/pixel already, despite more than 17cm distance! I am pretty sure this lens will easily be much lower than previous best of 0.77μm/pixel sofar with 20° lens -- if I can find a way to provide some longer than 4 M12 extension rings extension ...


P.S:
Really time to clean v2 image sensor, this photo shows very fine structures as well as tiny hairs from keyboard area between digit keys and function keys:
Image


P.P.S:
This is the "microscope" with 17.5cm distance from lens to keyboard.
Nice that Realacc arm can easily go below aluminum alloy base:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Sat Apr 21, 2018 8:52 pm

It was good that I did not continue with small extension ring steps -- would have taken a long time.

I bought a 2m 16mm diameter plastic tube in building center, inner diameter is 14mm. This was small enough to hang that tube under v2 camera with M12 mount and 2 M12 mount extension rings. And it allowed that 70mm lense with 2 M12 extension rings to hang at bottom of that tube:
Image


The distance between lens and object (micro SD card adapter) is now 9cm. What you see here on the right is the dot of the i in "Micro", the bottom of the i starts left of the dot (I turned camera 90°).
Image


I am not able to measure diameter of i-dot exactly, but it is slightly less than 1mm. Image height of 8MP image is 2464, but that does not contain full dot. 2500 pixels will still not cover whole dot. So resolution is better(less) than 1/2500 = 0.4μm/pixel(!). And the lens can still be moved closer to object resulting in even better resolution by using a longer tube! I would bet that 0.1μm/pixel will be possible ...

Problem I see now is that getting better resolution makes it difficult to find anything to identify and/or measure.


P.S:
I just measured the distance between v2 camera image sensor and lens -- 28cm!
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1614
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Creating a RPI-assisted microscope

Sun Apr 22, 2018 5:46 pm

On this photo you can see the tubes of different length I tried yestderday evening:
Image


Today I did measure each of them on distance image sensor to lens and distance lens to object, including the new tube you can see mounted in the photo (cm units):

Code: Select all

17.5/11.3 20/11 23/10 28/9 40/8

With 0.4μm/pixel or below light is a challenge to get a good image.Today I was not able get a good photo for 40/8 setup. Bright light was not the solution (I used 1000lm lamp). So I tried a small UV light, and got a much better image:
Image


The image shows two 0.5mm distant pins of FPC to DIP adapter board I used before for taking best 20° lens resolution of 0.77μm/pixel image:
viewtopic.php?f=43&t=45887&p=1298451#p1298451

I measured the distance between middle of pins as 2044 pixels. New best resolution is 0.245μm/pixel(!).
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”