当前位置:网站首页>Crop disease detection using image processing technology and convolutional neural network (CNN)
Crop disease detection using image processing technology and convolutional neural network (CNN)
2022-06-11 18:52:00 【woshicver】

ad locum , We will discuss the use of OpenCV Image processing technology to detect the severity of crop diseases . This process does not involve any part of the training . Based on color segmentation technology , We only extract healthier plant areas . The disease severity was calculated according to the total plant area and the healthier area .
So , I used some potato plant images
Calculation of plant disease severity based on image segmentation .

What is? OpenCV?
OpenCV It is an image processing software tool or library used to perform machine learning and computer vision tasks . The library comes with a set of built-in scripts to perform image analysis 、 Image detection, etc . This tool is mainly used for object tracking 、 Image analysis 、 The image processing 、 Face recognition, etc
What is? HSV Color ?
H - tonal , Is the color component ( Basic colors ), Range 0-180 S - saturation , Is the size of the color depth , Range 0-255 V - The brightness of the color , Range 0-255


HSV Is a color format , Such as RGB. The picture shows HSV Color map of . And RGB comparison , It's easy to get from HSV Extract the desired color region from the image in .HSV The image is not affected by light or climate change .
Morphological operation
Morphological transformation or operation is a simple operation performed on an image , To make some morphological changes in the image . This operation is performed on a single channel image . This operation requires 2 Input for processing , One is binary image , The other is called kernel The structural elements of . In order to perform this operation , A kernel of known size is used to convolute the image . The type of operation generally depends on the type of kernel we use . Corrosion and swelling are two basic morphological operations . In this project , We used the morphological open operation .
corrosion
Corrosion is a morphological operation performed on an image . The basic intuition of this operation is that it uses kernel corruption images . After the image is corroded , The noise is removed , But it also compresses the image .
The input to this operation is the containing value 0 or 1 Binary image of . A kernel of known size slides over the image . During this operation , If all pixels of the kernel are 1, Then the pixels of the original image under the kernel will be treated as 1, Otherwise it will be corroded ( To zero ). This procedure is used to remove small pixels from the image ( noise ).

inflation
Inflation is a morphological operation , But contrary to the corrosion performed on the image . This also takes binary images as input . In this operation , Only if at least one pixel of the kernel is 1 when , The pixels of the original image will be treated as 1. This action enlarges the white area , Corrosion reduces the white area .

The combination of these operations helps eliminate unwanted noise . Erosion removes white dots from an image ; It's basically noise , But the objects in the image will shrink . therefore , We use the bulge operation to inflate it to reshape it into its original shape .
Morphological open operation
When performing corrosion calculation before expansion , This process is called Morphological open operation .
The proposed image segmentation algorithm uses OpenCV( Image processing software tools ) To perform the task . The algorithm consists of three steps , Color segmentation 、 Morphological operation and severity calculation .

The severity of plant disease is the use of python Image processing technology in .
The calculation steps are as follows :
1. Loading pictures
The images used are downloaded from the Internet . Use cv2.imread Load the image and resize it to 250x250x3
2. take BGR Image to HSV Images
3. Extract healthy areas ( Green pixels )
Mask the original image to HSV Range to extract healthy areas (H:38–86,S:0-255,V:0–255)
4. Apply morphological operations
OpenCV The morphological operation in is a combination of first corrosion and then expansion . This is done to remove unwanted point pixels from the image ( noise )
5. Extract plant areas
Use HSV Range mask the image to extract the entire plant area (H:26–86, S: 0–255, V:0–255)
notes :HSV Values can be changed as required

chart :a- Actual image 、b-hsv Images 、c- Plant area 、d- Plant health areas 、 Of a plant area e-binary Images 、f- Binary images of plant health areas

chart :a- Actual image 、b-hsv Images 、c- Plant area 、d- Plant health areas 、 Of a plant area e-binary Images 、f- Binary images of plant health areas
6. Calculate the severity of the disease
The severity of the disease is calculated using ,

S= Disease severity ((0-1)0- low ,1- high )
HR= Area of plant health area
PR= The area of the entire plant area
import cv2, time
import numpy as np # numeraical
start = time.time() # to calculate the run tie required
img = cv2.imread("path/to/image file) # image reading
img=cv2.resize(img,(250,250)) # image resizing
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) # Converting it to hue saturation value image
range1=(26,0,0)
range2=(86,255,255)
mask1=cv2.inRange(hsv,range1,range2)
#apply morphological operations
kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5,5)) # create structuring element
mask2 = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, kernel1) # Apply mask to images
mask2 = cv2.morphologyEx(mask1, cv2.MORPH_CLOSE, kernel1) # Apply morphological
# open and close function
res=cv2.bitwise_and(img,img,mask=mask2) # these are done to display images
range1, range2 = (38,0,0), (86,255,255)
mask = cv2.inRange(hsv,range1,range2)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7,7))
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
t=mask
mask = cv2.merge([mask,mask,mask])
mask_inv = 255 - mask
white = np.full_like(img, (255,255,255))
img_masked = cv2.bitwise_and(img, mask)
white_masked = cv2.bitwise_and(white, mask_inv)
result = cv2.add(img_masked, mask_inv)
cv2.imwrite("green_plant_mask.png", t)
cv2.imwrite("green_plant_white_background.jpg", result)
cv2.imwrite("plant_region.jpg", res)
cv2.imwrite("binary.jpg",mask1)
cv2.imwrite("hsv_image.jpg",hsv)
x=cv2.countNonZero(t)
y=cv2.countNonZero(mask2)
print(x,y)
print("severity of disease is {}".format(1-(x/y)))
end = time.time() # to stop the time and to calculate runtime
print(f"Runtime of the program is {end - start} seconds")
cv2.imshow("img",img)# to display original image
cv2.imshow("binary", mask1) # to display binary image
cv2.imshow("hsv", hsv) # to display hsv image
cv2.imshow("result", result) # to display finalimage
# cv2.imshow("res",res)
# cv2.imshow("t",t)
cv2.waitKey(0)
cv2.destroyAllWindows()
Use opencv The quantification of the severity of plant diseases by image processing technology performs well in calculating the level of plant infection . The algorithm can calculate the disease severity of any plant .
The following figure shows the output of three different development technologies . Shoot healthy 、 Lightly infected and highly infected plant images to test the algorithm . this 3 The disease severity of the images was calculated as 0.04、0.22 and 0.98. For healthier plants ,4% The severity of is acceptable , This may be due to some light changes .

This technology is evaluated by visualizing the output results with the actual input images . The algorithm can calculate the disease severity of plants by applying morphology and color segmentation . The output range of the algorithm is 0 To 1.
The developed technology has been tested on local machines and raspberry pie models . The running time in both cases is less than 0.1 second . therefore , This technology will be more effective in calculating the instantaneous severity of plants and applying pesticides to unhealthy plants more accurately .
* END *
If you see this , Show that you like this article , Please forward 、 give the thumbs-up . WeChat search 「uncle_pn」, Welcome to add Xiaobian wechat 「 woshicver」, Update a high-quality blog post in your circle of friends every day .
↓ Scan QR code and add small code ↓

边栏推荐
- cf:D. Black and White Stripe【连续k个中最少的个数 + 滑动窗口】
- KMP!你值得拥有!!! 直接运行直接跑!
- 美国通胀率8.6%创41年历史新高!通胀高烧不退?股票、加密市场先跌为敬!
- Force deduction 23 questions, merging K ascending linked lists
- Niu Ke swipes the question -- converting a string to an integer
- 信号的处理与捕捉
- leetcode:剑指 Offer 56 - II. 数组中数字出现的次数 II【简单排序】
- 北京邮电大学2023级工商管理硕士MBA(非全日制)已开启
- Analysis of runtime instantiation of XML view root node in SAP ui5
- Swagger2简单使用
猜你喜欢

Specific methods for JS to realize full screen display

Balanced search binary tree -- AVL tree

手把手教你学会FIRST集和FOLLOW集!!!!吐血收藏!!保姆级讲解!!!

Why is ti's GPMC parallel port more often used to connect FPGA and ADC? I give three reasons

Visual slam lecture notes-10-2

Labelme for image data annotation

力扣刷题——二叉树的层序遍历Ⅱ

2022-2023年西安交通大学管理学院MEM提前批面试网报通知
用户信息管理的功能开发

Cool visualization tool: first introduction to processing
随机推荐
Prevent enemy tanks from overlapping
Combination sum of 39 questions
力扣刷题——二叉树的层序遍历Ⅱ
*Use of jetpack notes room
leetcode:926. 将字符串翻转到单调递增【前缀和 + 模拟分析】
KMP! You deserve it!!! Run directly!
Overall process of software development
Signal processing and capture
cf:E. Price Maximization【排序 + 取mod + 双指针+ 配对】
Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics
Niu Ke's questions -- two sorting methods
Uploading and downloading of necessary files in development
leetcode:剑指 Offer 59 - II. 队列的最大值[deque + sortedlist]
Web3游戏:游戏体验的探寻与重塑
SQL injection vulnerability learning 1: phpstudy integrated environment building DVWA shooting range
kubernetes 二进制安装(v1.20.15)(八)部署 网络插件
Analysis of runtime instantiation of XML view root node in SAP ui5
2022-2023 MEM pre approval interview notice of School of management, Xi'an Jiaotong University
cf:G. Count the Trains【sortedset + bisect + 模拟维持严格递减序列】
Introduction to basic use and pit closure of BigDecimal