Bordering images with python Part 1

What you want to do

Well, I will summarize what I tried variously like this as a memorandum.

environment

Prerequisite knowledge


Image for testing

test.png

For the time being, I thought that it would be possible to do RGB images if I bite the image processing, so first I will use binary images. I challenged to take the edge of a complicated figure because the inside is missing.

code

Github Jupyter Notebook

Basic policy

  1. Make a dot inside the object you want to demarcate
  2. Draw a line outward from that point and find out where on that line the color changes.
  3. Rotate the line 360 degrees to get the boundary.

A simple image looks like this

↓ Detection target test01.png Detection result test01検出結果01.png It's almost taken.

However, depending on the position of the point, it becomes a shadow of the line and looks like this. test01検出結果02.png

I would like you to understand that the image at the beginning is a rather difficult task.

Test image detection result

test検出結果01.png test検出結果02.png test検出結果03.png test検出結果04.png test検出結果05.png

With one point, shadows can be created everywhere, and invisible areas can be created.

If there are multiple points, the shadow problem should be alleviated.

test検出結果06.png

Overdone w

Summary

The outer edging is roughly removed. Still, there are some areas that cannot be removed in the internal area, so improvement is required. But I don't think it's difficult to border with a Pezier curve with this much.

This time, I hit the dots randomly, so there were too many wasted hits, but it seems interesting to move the dots appropriately and remove the edges with the minimum number of dots. I wonder if I can use reinforcement learning. It will be an issue from the next time onwards.

Recommended Posts

Bordering images with python Part 1
Image processing with Python (Part 2)
Studying Python with freeCodeCamp part1
Scraping with Selenium + Python Part 1
Studying Python with freeCodeCamp part2
Image processing with Python (Part 1)
Solving Sudoku with Python (Part 2)
Image processing with Python (Part 3)
Scraping with Selenium + Python Part 2
Number recognition in images with Python
[Automation with python! ] Part 1: Setting file
Post multiple Twitter images with python
Animate multiple still images with Python
Load gif images with Python + OpenCV
[Python] Collect images easily with icrawler!
Automate simple tasks with Python Part0
[Automation with python! ] Part 2: File operation
Working with DICOM images in Python
Excel aggregation with Python pandas Part 1
QGIS + Python Part 2
FizzBuzz with Python3
Scraping with Python
Statistics with python
Play handwritten numbers with python Part 2 (identify)
FM modulation and demodulation with Python Part 3
Amplify images for machine learning with python
Process Pubmed .xml data with python [Part 2]
Scraping with Python
Python with Go
QGIS + Python Part 1
Automate simple tasks with Python Part1 Scraping
Capturing images with Pupil, python and OpenCV
Twilio with Python
Integrate with Python
Play with 2016-Python
100 Language Processing Knock with Python (Chapter 2, Part 2)
AES256 with python
Tested with Python
Working with Azure CosmosDB from Python Part.2
python starts with ()
Excel aggregation with Python pandas Part 2 Variadic
[python, openCV] base64 Face recognition with images
100 Language Processing Knock with Python (Chapter 2, Part 1)
with syntax (Python)
FM modulation and demodulation with Python Part 2
Python: Scraping Part 1
Bingo with python
[Python] Read images with OpenCV (for beginners)
Zundokokiyoshi with python
[Part1] Scraping with Python → Organize to csv!
Add Gaussian noise to images with python2.7
Importing and exporting GeoTiff images with Python
Read text in images with python OCR
Upload images to Google Drive with Python
Excel with Python
Python3 Beginning Part 1
Microcomputer with Python
Python: Scraping Part 2
Cast with python
Machine learning starting with Python Personal memorandum Part2
Create test data like that with Python (Part 1)