I'm looking for several days now how to solve my problem.
I want to calibrate my CCD pictures (FITS files) so that I can generate the FITS headertopics to di astrometry ib them.
I have a number of stars of which I know RA and DEC and I want to use this data to calculate the parameters to calibrate my photo. I found a web page that does excact what I need but the source code is not online:
http://www1.phys.vt.edu/~jhs/SIP/astrometrycalc.html
In AstroPy coordinate and WCS I find all the functions that I need to do my job but they all assume a fully completed FITS header and I do not have one. (the photos come from an SLR camera in RAW format)
My question is whether I overlook a function or someone who can put me on the road to calculate the header parameters so that I can complete it with the necessary data?
Who can deliver me from my suffering.
tnx
It sounds like you want to plate-solve your image and write the coordinate information and possibly other details into the FITS header.
Have you considered using Astrometry.net? There is a python client here.
You will need to convert your image from raw. Astrometry can handle fits, jpg, gif, and png formats. You can then use Astropy to update the fits header with the results from the Astrometry API. Details on how to work with FITS headers can be found here.
Related
I have a pair of coordinates (lat, long).
I need to generate an image of displaying these coordinates on the map.
And then generate such images with other coordinates in the future without the Internet.
Please tell me whether there are solutions that allow you to display coordinates offline?
Upd: is there any opportunity to download maps offline , eg: gps tracker maps or something like that?
thank you
This is not possible while offline. To generate an image of the coordinate location you would most likely be using
os.system("open \"\" https://www.google.nl/maps/place/" + location)
and then generating a image of the location that is popped up. This is impossible to do while offline, I am very sorry.
The question is too broad to give a good answer. However:
There are several companies, such as TeleAtlas and NavTeq, that sell map data. I have no idea what buying the world from them at 1:1M resolution would cost, but I'd guess several thousand USD.
You could download data, or pre-rendered rasters, from Natural Earth. However, they don't have quite the resolution required for good 1:1M maps.
You could download data from OpenStreetMap. The data is free (as in beer, and as in speech), but using it is a major undertaking.
There are companies that offer pre-rendered maps in various formats from OpenStreetMap data. OpenMapTiles is the one I happen to have at the top of my head, but here are others.
I am trying to detect and extract the "labels" and "dimensions" of a 2D technical drawing which is being saved as PDF using python. I came across a python library call "pytesseract" which has optical character recognition capability. I tried the demo on my image but it fails to detect most of the label/dimensions. Please suggest if there is other way to do it. Thank you**.
** Attached is a sample of the 2D technical drawing I try to detect
** what I am trying to achieve is to able to obtain the coordinate of every dimensions (the 160,120,10 4x45 etc) on the image, and extract the, as well.
About 16 months ago we asked ourselves the same question.
If you want to implement it yourself, I'd suggest the following process:
Extract the Canvas from the sheet
Separate the Cuts
Detect the Measure Regions on each Cut
Detect the individual attributes of the Measure Regions to understand where the Measure Start & End. In your particular example that's relatively easy.
Run the detected Measure Labels through OCR
Associate the Labels to the Measures
Verify your results
Alternatively you can also run it through our API and get the results as JSON.
Here's a quick visualization of the result:
Drawing Read (GT stands for General Tolerances)
I want to extract the geopgraphic coordinates from a smartphone picture. All our photos are georeferenced and that info is embedded in headers somewhere. Is there a matlab or python function that can tell me a pictures geographic coordinates?
I want to write a script which can calculate the distance between the two images, so if I can extract geographic coordinates of the two photos then I will be able to calculate the distance.
thanks
If you want to use MATLAB, there is a function called imfinfo that extracts the exif data from an image file and saves it in a struct. You can find the GPS information in the GPSInfo field. Example:
info = imfinfo('filename.png');
info.GPSInfo
Then, to access the individual Latitude and Longitude values (expressed in degrees, minutes, seconds) you can check the fields GPSLatitude and GPSLongitude:
info.GPSInfo.GPSLatitude
info.GPSInfo.GPSLongitude
I would suggest looking into http://python-pillow.org
The following pillow documentation gives you are starting point to get what you are looking for.
https://pillow.readthedocs.io/en/latest/reference/ExifTags.html#exiftags-module
Are you allowed to use external tool?
Use jpegsnoop or exiftools to extract a txt file. I can't remember the exact commands but you can find it easily. Both tools have executables and code available. Personally, I like jpegsnoop better.
system('jpegsnoop.exe image/path ... output_image.txt);
Read the txt file which contains geo-tags. There might be up to 7 tags, different camera brands use different tags. Among those, will choose geolocation (I cant recall the exact name but it contains longitute and lattitude in the name).
You can do this by a simple while loop:
while (line = readline) ~= EOF
if line.startsWith (geo-tags)
print line %or add to cell array etc.
To my experience, python is not as good as jpegsnoop.
As NaN mentioned, make sure the gps is on when you take the picture from the smart phone.
I am creating a database from historical records which I have as photographed pages from books (+100K pages). I wrote some python code to do some image processing before I OCR each page. Since the data in these books does not come in well formatted tables, I need to segment each page into rows and columns and then OCR each piece separately.
One of the critical steps is to align the text in the image.
For example, this is a typical page that needs to be aligned:
A solution I found is to smudge the text horizontally (I'm using skimage.ndimage.morphology.binary_dilation) and find the rotation that maximizes the sum of white pixels along the horizontal dimension.
This works fine, but it takes about 8 seconds per page, which given the volume of pages I am working with, is way too much.
Do you know of a better, faster way of accomplishing aligning the text?
Update:
I use scikit-image for image processing functions, and scipy to maximize the count of white pixels along the horizontal axis.
Here is a link to an html view of the Jupyter notebook I used to work on this. The code uses some functions from a module I've written for this project so it cannot be run on its own.
Link to notebook (dropbox): https://db.tt/Mls9Tk8s
Update 2:
Here is a link to the original raw image (dropbox): https://db.tt/1t9kAt0z
Preface: I haven't done much image processing with python. I can give you an image processing suggestion, but you'll have to implement it in Python yourself. All you need is a FFT and a polar transformation (I think OpenCV has an in-built function for that), so that should be straightforward.
You have only posted one sample image, so I don't know if this works as well for other images, but for this image, a Fourier transform can be very useful: Simply pad the image to a nice power of two (e.g. 2048x2048) and you get a Fourier spectrum like this:
I've posted a intuitive explanation of the Fourier transform here, but in short: your image can be represented as a series of sin/cosine waves, and most of those "waves" are parallel or perpendicular to the document orientation. That's why you see a strong frequency response at roughly 0°, 90°, 180° and 270°. To measure the exact angle, you could take a polar transform of the Fourier spectrum:
and simply take the columnwise mean:
The peak position in that diagram is at 90.835°, and if I rotate the image by -90.835 modulo 90, the orientation looks decent:
Like I said, I don't have more test images, but it works for rotated versions of your image. At the very least it should narrow down the search space for a more expensive search method.
Note 1: The FFT is fast, but it obviously takes more time for larger images. And sadly the best way to get a better angle resolution is to use a larger input image (i.e. with more white padding around the source image.)
Note 2: the FFT actually returns an image where the "DC" (the center in the spectrum image above) is at the origin 0/0. But the rotation property is clearer if you shift it to the center, and it makes the polar transform easier, so I just showed the shifted version.
This is not a full solution but there is more than a comment's worth of thoughts.
You have a margin on the left and right and top and bottom of your image. If you remove that, and even cut into the text in the process, you will still have enough information to align the image. So, if you chop, say 15%, off the top, bottom, left and right, you will have reduced your image area by 50% already - which will speed things up down the line.
Now take your remaining central area, and divide that into, say 10 strips all of the same height but the full width of the page. Now calculate the mean brightness of those strips and take the 1-4 darkest as they contain the most (black) lettering. Now work on each of those in parallel, or just the darkest. You are now processing just the most interesting 5-20% of the page.
Here is the command to do that in ImageMagick - it's just my weapon of choice and you can do it just as well in Python.
convert scan.jpg -crop 300x433+64+92 -crop x10# -format "%[fx:mean]\n" info:
0.899779
0.894842
0.967889
0.919405
0.912941
0.89933
0.883133 <--- choose 4th last because it is darkest
0.889992
0.88894
0.888865
If I make separate images out of those 10 stripes, I get this
convert scan.jpg -crop 300x433+64+92 -crop x10# m-.jpg
and effectively, I do the alignment on the fourth last image rather than the whole image.
Maybe unscientific, but quite effective and pretty easy to try out.
Another thought, once you have your procedure/script sorted out for straightening a single image, do not forget you can often get massive speedup by using GNU Parallel to harass all your CPU's lovely, expensive cores simultaneously. Here I specify 8 processes to run in parallel...
#!/bin/bash
for ((i=0;i<100000;i++)); do
ProcessPage $i
done | parallel --eta -j 8
"align the text in the image" I suppose means to deskew the image so that text lines have the same baseline.
I thoroughly enjoyed reading scientific answers to this quite overengineered task. Answers are great, but is it really necessary to spend so much time (very precious resource) to implement this? There is an abundance of tools available for this function without needing to write a single line of code (unless OP is a CS student and wants to practice the science, but obviously OP is doing this out of necessity to get all images processed). These methods took me back to my college years, but today I would use different tools to process this batch quickly and efficiently, which I do daily. I work for a high-volume document conversion and data extraction service bureau and OCR consulting company.
Here is the result of a basic open and deskew step in ABBYY FineReader commercial desktop OCR package. Deskewing was more than sufficient for further OCR processing.
And I did not need to recreate and program my own browser just to post this answer.
What I want to do is to generate a static image (e.g. a png) using python and using openstreetmap tiles as a background.
Mathplotlib and Basemap is almost what I'm looking for. The problem is being able to use OSM tiles as background. I'm not pleased by the approach suggested in http://stevendkay.wordpress.com/2010/02/24/plotting-points-on-an-openstreetmap-export/
The closest I found is in this answer but using R, and not python Plotting points from a data.frame using OpenStreetMap
Did I miss any obvious and easy solution?
Thanks for your help
EDIT : this questions suggests many tools, but none seems to match my needs How can I display OSM tiles using Python?
You overlooked the "Export" tab at the OSM website, which is capable of generating a static image with the dimensions and map extents you want. Have a look at http://wiki.openstreetmap.org/wiki/Export
Please be advised that generating static images is a resource-intensive process, and the OSM sysadmins will frown upon you if you do a large number of requests or abuse this feature. Unfortunately this means you'll have to find another solution if you're trying to do lots of images.
By the way, the data you're plotting on top is properly projected into EPSG:3857 and not just raw lat/lon coordinates, right? Raw lat/lon data will look distorted at large zoom levels.