ITMO-HDU Image Processing Lab4 Report
Image Processing
LabNo4\mathbf{Lab\space No4}Lab No4
StudentInfo\mathbb {Student\space Info}Student Info
Name: Xiao Shitong
HDU ID: 19321123
ITMO ID: 293647
Content
文章目录
- Purpose\mathbb{Purpose}Purpose
- Theory\mathbb{Theory}Theory
- Basicmorphologicaloperations\mathbb{Basic\space morphological\space operations}Basic morphological operations
- Separatingobjects\mathbb{Separating\space objects}Separating objects
- Watershedsegmentation\mathbb{Watershed\space segmentation}Watershed segmentation
- Assignmentprogress\mathbb{Assignment\space progress}Assignment progress
- Basicoperations\mathbb{Basic\space operations}Basic operations
- Originalimages\mathbb{Original\space images}Original images
- Resultimages\mathbb{Result\space images}Result images
- Code\mathbb{Code}Code
- Comments\mathbb{Comments}Comments
- Separatingobjects\mathbb{Separating\space objects}Separating objects
- Originalimage\mathbb{Original\space image}Original image
- Resultimage\mathbb{Result\space image}Result image
- Code\mathbb{Code}Code
- Comments\mathbb{Comments}Comments
- Watershedsegmentation\mathbb{Watershed\space segmentation}Watershed segmentation
- Originalimage\mathbb{Original\space image}Original image
- Resultimage\mathbb{Result\space image}Result image
- Code\mathbb{Code}Code
- Comments\mathbb{Comments}Comments
- Conclusion\mathbb{Conclusion}Conclusion
- Answers\mathbb{Answers}Answers
Purpose\mathbb{Purpose}Purpose
- Getting know about basic digital images morphological analysis principles
- Using basic digital images operations
- Combine them to implement object splitting algorithm
Theory\mathbb{Theory}Theory
Basicmorphologicaloperations\mathbb{Basic\space morphological\space operations}Basic morphological operations
Dilation
A⊕BA\oplus BA⊕B, where A is a binary image and B is an structural element. Its calculation formula can be written as dst(x,y)=max(src(x+x′,y+y′)),(x′,y′):element(x′,y′)≠0dst(x,y) = max (src(x+x', y+y')), (x',y'):element(x',y') \neq 0dst(x,y)=max(src(x+x′,y+y′)),(x′,y′):element(x′,y′)=0
Erosion
The simliar operation as dilation, but the maxmaxmax function in formula changes to minminmin function. Thus, it’s A⊖BA\ominus BA⊖B, and the calculation formula is dst(x,y)=max(src(x+x′,y+y′)),(x′,y′):element(x′,y′)≠0dst(x,y) = max (src(x+x', y+y')), (x',y'):element(x',y') \neq 0dst(x,y)=max(src(x+x′,y+y′)),(x′,y′):element(x′,y′)=0
Open
Open operation is a combination of dilation and erosion. It can be written as (A⊖B)⊕B(A\ominus B)\oplus B(A⊖B)⊕B.
This operation can be used to remove small objects, split object by the thin junction.
Close
Close operation is also a combination of dilation and erosion. It can be written as (A⊕B)⊖B(A\oplus B)\ominus B(A⊕B)⊖B.
This operation can be used to remove some little black holes in the image.
Bwareaopen
This operation can be used to remove small connectivity object from the image.
Contour detection
Contour consists of internal contour and external contour.
For the internal contour detection, the formula is A−(A⊖B)A - (A\ominus B)A−(A⊖B).
For the external contour detection, the formula is A−(A⊕B)A - (A\oplus B)A−(A⊕B).
Separatingobjects\mathbb{Separating\space objects}Separating objects
- First, we should change the gray image into binary value image.
- Then, we erode this binary value image and got one image whose object areas are smaller.
- We do several dilation operation, we can detect the approximate contour between objects.
- Last, we just combine the contour together with the original gray image. Thus, the result image will look like separating the objects.
Watershedsegmentation\mathbb{Watershed\space segmentation}Watershed segmentation
The watershed segmentation algorithm assume that the garyscale image as a geological watershed.
And the value of gary pixel is regarded as the altitude, where higher altitude means much whiter.
Then we drop water into the watershed, and the lower altitude will be first drown, and then higher altitude. During the dropping, we can add isolation between each puddle. Thus, we can separate the objects.
Assignmentprogress\mathbb{Assignment\space progress}Assignment progress
Basicoperations\mathbb{Basic\space operations}Basic operations
Originalimages\mathbb{Original\space images}Original images
Chinese characters | Photo |
---|---|
Resultimages\mathbb{Result\space images}Result images
Erosion | Dilation | Open | Close | Bwarea open | Internal contour | External contour |
---|---|---|---|---|---|---|
Code\mathbb{Code}Code
# Do erode and dilate
kernel = cv.getStructuringElement(cv.MORPH_RECT, (15, 15))chinese_eroded = cv.erode(chinese, kernel)
cv.imshow("chinese eroded", chinese_eroded)chinese_dilated = cv.dilate(chinese, kernel)
cv.imshow("chinese dilated", chinese_dilated)# Do open and close
kernel = cv.getStructuringElement(cv.MORPH_RECT, (15, 15))chinese_closed = cv.morphologyEx(chinese, cv.MORPH_CLOSE, kernel, iterations=1)
cv.imshow("chinese closed", chinese_closed)chinese_opened = cv.morphologyEx(chinese, cv.MORPH_OPEN, kernel, iterations=1)
cv.imshow("chinese opened", chinese_opened)chinese_opened_closed = cv.morphologyEx(chinese_opened, cv.MORPH_CLOSE, kernel, iterations=2)
cv.imshow("chinese opened closed", chinese_opened_closed)# Do bwarea open
photo_bwareaopen = utils.bwareaopen(photo, 20000)
cv.imshow("photo bwareaopen", photo_bwareaopen)#
chinese_inner_contour = cv.subtract(chinese, chinese_eroded)
cv.imshow("Inner contour (I - erosion)", chinese_inner_contour)
chinese_outer_contour = cv.subtract(chinese_dilated, chinese)
cv.imshow("Outer contour (dilation - I)", chinese_outer_contour)# End of basic operations
Comments\mathbb{Comments}Comments
For the digital images morphological operations, the erosion and dilation are the basical operations for other operations. The open, close and bwarea open operations are based on the combination of erosion and dilation.
Separatingobjects\mathbb{Separating\space objects}Separating objects
Originalimage\mathbb{Original\space image}Original image
Resultimage\mathbb{Result\space image}Result image
Binary value coins | Erosion | Contour | Result |
---|---|---|---|
Code\mathbb{Code}Code
coins = cv.cvtColor(coins_color, cv.COLOR_BGR2GRAY
retval, coins_threshold = cv.threshold(coins, 160, 255, cv.THRESH_BINARY_INV) # Make it change into binary image
kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (5, 5))# Erode
coins_threshold_eroded = cv.morphologyEx(coins_threshold, cv.MORPH_ERODE, kernel, iterations=14, borderType=cv.BORDER_CONSTANT, borderValue=(0)) # Erode the binary image then after several dilations, the contour can be detected
cv.imshow("coins_threshold_eroded", coins_threshold_eroded)# Dilate
T = np.zeros_like(coins_threshold)
while cv.countNonZero(coins_threshold_eroded) < coins_threshold_eroded.size:dilated = cv.dilate(coins_threshold_eroded, kernel, borderType=cv.BORDER_CONSTANT, borderValue=(0))closed = cv.morphologyEx(dilated, cv.MORPH_CLOSE, kernel, borderType=cv.BORDER_CONSTANT, borderValue=(0))split = cv.subtract(closed, dilated)T = cv.bitwise_or(split, T)coins_threshold_eroded = dilated# Border close
kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (3, 3))
T = cv.morphologyEx(T, cv.MORPH_CLOSE, kernel, iterations=14, borderType=cv.BORDER_CONSTANT, borderValue=(255))
T_eroded = cv.morphologyEx(~T, cv.MORPH_ERODE, kernel, iterations=1)
T_contour = cv.subtract(~T, T_eroded)
cv.imshow("T", T)# Remove border
coins_threshold = cv.bitwise_and(~T, coins_threshold)
coins_threshold[T_contour > 0] = 255
result = cv.bitwise_and(coins_threshold, coins)cv.imshow("result", result)
Comments\mathbb{Comments}Comments
First, we should convert the original image into gray scale, and then change it into binary value image via implementing threshold filter.
Then we should remove some small noise on the image, so that these small noises won’t cause bad effect in the coming contour detection.
After that, we can use several steps of dilation, so that we can find the contours between coins.
Then, we can add contour onto the original gray coins images. So that, we implement the separating objects.
Watershedsegmentation\mathbb{Watershed\space segmentation}Watershed segmentation
Originalimage\mathbb{Original\space image}Original image
Resultimage\mathbb{Result\space image}Result image
Code\mathbb{Code}Code
coins_gray = cv.cvtColor(coins_color, cv.COLOR_BGR2GRAY)
ret, thresh = cv.threshold(coins_gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)# noise removal
kernel = np.ones((9, 9), np.uint8)
opening = cv.morphologyEx(thresh, cv.MORPH_OPEN, kernel, iterations=2)# sure background area
sure_bg = cv.dilate(opening, kernel, iterations=3)# Finding sure foreground area
dist_transform = cv.distanceTransform(opening, cv.DIST_L2, 5)
cv.imshow("distance", dist_transform)
ret, sure_fg = cv.threshold(dist_transform, 0.7 * dist_transform.max(), 255, 0)# Finding unknown region
sure_fg = np.uint8(sure_fg)
unknown = cv.subtract(sure_bg, sure_fg)# Marker labelling
ret, markers = cv.connectedComponents(sure_fg)# Add one to all labels so that sure background is not 0, but 1
markers = markers + 1# Now, mark the region of unknown with zero
markers[unknown == 255] = 0markers = cv.watershed(coins_color, markers)
coins_color[markers == -1] = [255, 0, 0]cv.imshow("Result", coins_color)
Comments\mathbb{Comments}Comments
The basic algorithm about watershed has been already told in theory part.
But when implementing it, we should also remove small noises, just as part 2 of work.
Conclusion\mathbb{Conclusion}Conclusion
When we work with digital images morphological operations, we are actually working with erosion, dilation and their various combinations.
Answers\mathbb{Answers}Answers
Does the opening result include the closing result?
The calculation of open operation is (A⊖B)⊕B(A\ominus B)\oplus B(A⊖B)⊕B, and the calcution of close operation is (A⊕B)⊖B(A\oplus B)\ominus B(A⊕B)⊖B. There is no connection between these two operations.What morphological filter should be applied to remove ledges from an object?
Open.How can you find the object edges using morphological operations?
Use formula: A′=A−(A⊖B)A' = A - (A\ominus B)A′=A−(A⊖B).What is morphology?
Morphology is one brunch of image processing, where the color and brightness are not important factors.We only take care of the shape and position of objects.
ITMO-HDU Image Processing Lab4 Report相关推荐
- Awk by Example--转载
原文地址: http://www.funtoo.org/Awk_by_Example,_Part_1?ref=dzone http://www.funtoo.org/Awk_by_Example,_P ...
- linux 网站访问日志,网站访问日志的管理--analog使用
analog是一款功能强大的开源的网站访问日志分析软件,支持多语言,可以运行在linux,windows下,支持apache及iis日志,下面以linux+apache为例,介绍其基本用法 安装 an ...
- 无源光网络PON的原理
一.光纤接入网的接入方案 (a) P2P,点对点的网络传输成本太高,浪费光纤资源. (b) 光纤到路边交换机,降低了传输成本,但是在接入侧增加了带电设备,增加了故障点,也相应的增加了维护成 ...
- 华为光猫电源power,pon、los、lan,引出 无源光网络PON的原理
2019独角兽企业重金招聘Python工程师标准>>> 无源光网络(Passive Optical Network ,PON) 主要采用无源光功率分配器(耦合器)将信息送至各用户.由 ...
- 实验记录 | mutect问题详解:No tribble type was provided on the command line and the type of the file?
出错详情: /home/xxzhang/workplace/software/java/jdk1.7.0_80/bin/java -Djava.io.tmpdir=./output_RNA/mutmp ...
- IBASE archive write processing report RIBARCHA
Created by Jerry Wang, last modified on Sep 09, 2014 pre processing执行完毕后,执行write report: 执行完毕后显示achi ...
- Crystal Reports Maximum Report Processing Jobs Limit
水晶报表最大进程数限制问题 Solutions A solution to the print jobs processing limit vary depending on the cause. O ...
- 解决rdlc报错 An error occurred during local report processing
转自VC错误:http://www.vcerror.com/?p=1597 问题描述: 从VS2005升级到2012或者2013后,原来做的报表,如果编辑过,而且不是转换成XML而是用编辑模式的话,会 ...
- rdlc报表An error occurred during local report processing错误
在开发环境的电脑上可生成报表,但是一到客户端就提示An error occurred during local report processing错误. 猜想是缺dll,补充上 Microsoft.R ...
- VS 2013使用ReportViewer 提示An error occurred during local report processing异常处理
VS 2013使用ReportViewer 提示An error occurred during local report processing异常处理 参考文章: (1)VS 2013使用Repor ...
最新文章
- 进程 线程 协程_进程,线程,协程那些事
- 2014.8.30.ref,out,params,enum,递归
- 抖音小程序开发:CEO们涌进直播间带货
- 在有限多的不大于100的正整数中,找出尽量多个相加起来值介于98~102之间的组合...
- CSDN云计算是什么?云计算可以应用在哪些方面?
- 成功加入微软GDI计划
- 注册表添加 右键功能
- MSP430 PIN 操作寄存器
- 电路设计中发光二极管用作指示灯时的限流电阻如何选择
- sop28和so28j封装_sop28封装尺寸
- 盗版windows7危害大
- postfix 测试邮件服务器,搭建Postfix邮件服务器
- 解决精灵标注助手暂不支持导入pascal文件
- Java 程序员,年薪 40W 需要什么水平?
- GBase 8d条目添加到模板
- 设计模式学习笔记(一):抽象工厂
- 环保材料营造健康氛围
- WiFi、WiMAX、WBMA与3G的比较
- 【MATLAB】通过MATLAB提供的函数产生矩阵
- 腾讯云服务器使用教程,手把手教你入门