Python: Crop out area from image along borders

Python: Crop out area from image along borders



What functions (and how I should use them) should I use to crop out the center part of this image? I want to take just the less-dense parts, not the dense borders.



Thanks!



In the end, I want to either count the tiny circles/dots (cells) in the areas or calculate the area of the less-dense parts, outlined in the second image. I've done this before with ImageJ by tracing out the area by hand, but it is a really tedious process with lots of images.



Original



Area traced



I've currently looked at Scipy, but they are big and I don't really know how to approach this. If someone would point me in the right direction, that would be great!





Does the crop have to have a curved boundary or can you approximate it as a rectangle? As far as the bubbles go you may check out the OpenCV library. OpenCV has a some functions for blob detection that you might be able to automatically detect the bubbles.
– Abstracted
Aug 25 at 4:24




1 Answer
1



It would take me a bit longer to do in Python, but I tried a few ideas just on the command-line with ImageMagick which is installed on most Linux distros and is available for free for macOS and Windows.



First, I trimmed your image to get rid of extraneous junk:



enter image description here



Then, the steps I did were:



That command looks like this in Terminal/Command Prompt:


convert blobs.png -alpha off -colorspace gray -normalize -threshold 50% -statistic mean 49x49 -threshold 90% result.png



The result is:



enter image description here



If that approach looks promising for your other pictures we can work out a Python version pretty quickly, so let me know.



Of course, if you know other useful information about your image that could help improve things... maybe you know the density is always higher at the edges, for example.



In case anyone wants to see the intermediate steps, here is the image after grey scaling and normalising:



enter image description here



And here it is after blurring:



enter image description here





Mark, I cannot reproduce your result from your command using IM 6.9.10.10 Q16 Mac OSX. Did you perhaps forget something or change any values from what you wrote. There is also an outer white border in the original input that may need to be removed.
– fmw42
Aug 25 at 18:15






@fmw42 Sorry, yes - I forgot that bit because I ent out and did something else in the middle of answering. The original image was poorly trimmed. I'll add the trimmed one for you to play with.
– Mark Setchell
Aug 25 at 19:08






Thanks, now it seems to work. But if you look closely, there is a small white region in the bottom right corner. You can remove that with -morphology open octagon:2 at the end of your command.
– fmw42
Aug 25 at 21:03



-morphology open octagon:2





@fmw42 Yes, thanks Fred. At the moment, I have no way of knowing whether this approach is optimal for the OP as I have only seen one image - it could fall flat on its face with other images so I'll await feedback before optimising and fine-tuning prematurely! Thank you, I always appreciate your inputs.
– Mark Setchell
Aug 26 at 10:58






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế