Improving The Quality of Handwritten Image Segmentation Using K-Means Clustering Algorithms With Spatial Filters
Improving The Quality of Handwritten Image Segmentation Using K-Means Clustering Algorithms With Spatial Filters
Corresponding Author:
Muhammad Munsarif
Department of Informatics, Universitas Muhammadiyah Semarang
Kedungmundu Raya street No. 18, Semarang, Indonesia
Email: [email protected]
1. INTRODUCTION
Handwriting is the result of human work that has unique characteristic that differs from each other.
Graphology experts [1] or graphologists analyze human characters and personalities by observing
handwriting patterns visually or directly [2]. An individual’s behaviour is the reflection of his/her personality.
Changes or fluctuations in behaviour or emotions may be seen while examining one’s handwriting. Such
changes in moods can be encountered from an individual’s handwriting as well. Generally, graphologists
predict human characters by considering handwriting characteristics and investigating writing pressures,
letter spacing, slope with the baseline parameters, the letter-slant, height of the T-bar, and width of margins.
The results of this analysis have been utilized in psychology, education, criminology, and medicine [3], [4].
Identification of such behavioural traits are possible using graphology and applications in several domains for
handwriting-based personality have been explored [5]. The improvement of the accuracy requires an
information technology that can help graphologists interpret handwritten images by using image processing
techniques [6]. One of the important steps in image processing is the segmentation process that aims to
separate backgrounds from objects. Human handwriting has different styles and shapes. The quality of
handwritten images crucially determines the nature of one's personality; thus, good quality of an image is
necessary [7].
Segmentation is a step to partition an image into different regions by creating boundaries that
separate areas. At the same time, one of the most frequently used steps is pixel zoning of an image [8]. Image
segmentation aims to divide an image into segments with similar features or attributes [9]. Edge-based
segmentation techniques can identify essential things, namely corners, edges, points, and lines in the image.
However, in some cases, there are pixel categorization errors in the edge-based segmentation category.
Therefore, one of the edge detection techniques is the segmentation method [10]. Many studies have
considered k-means to maximize the efficiency of the algorithm [11]. This algorithm performs unattended
clustering in favor of their inherent distance from each other, which classifies the input data points into
several categories [12]. Where the iterative algorithm minimizes the number of geometric distances between
the centroid cluster and each object. This research improved the quality of handwritten image segmentation
using k-means clustering algorithms with the spatial filter. The k-means algorithm is used for image
segmentation. The image has been changed to a grayscale image then facilitates cluster extraction. To
measure the performance of the segmentation results, the silhouette coefficient was calculated [13]. In the
K-mean clustering algorithm: divide the image into K groups and add points [14]. The silhouette coefficient
method is a measurement method that combines cohesion with separation to determine the quality of clusters.
Image segmentation is done by using the k-means clustering method. It is one of the algorithms to classify
some cluster regions by considering certain characteristics [15]. The Efficient image segmentation and
implementation of k-means clustering is urgently needed [16].
A lot of research on image segmentation uses techniques from conventional and based learning
methods, where the k-means algorithm is one of the simplest to generate an exciting region [17], [18]. The
followings are some previous research investigating the processing of handwritten images. Brodowska
examined handwritten image segmentation and employed several approaches, such as holistic, classic,
recognition-based segmentation, and mixed approaches. The approaches were selected depending on the
types of alphabets and characters read [19]. Nath and Rastogi [20] developed some stages in optical character
recognition (OCR). The segmentation was done using the explicit and implicit approaches. Meanwhile, the
classification is done by varying some features. Choudhary et al. [21] observed a handwritten image
segmentation using an object or region selection-based approach that meets the criteria of width above the
limit values. The extraction was performed on each character. Meanwhile, words with different sizes were
considered as the background that made noise. Choudhary et al. [22] also developed a new technique for
vertical segmentation in which the segmentation was performed per pixel after the characters had been
depleted to get the character sizes. This technique improved the quality of word segmentation on handwritten
images; thus, the problems in the open character segmentation were minimized. Rani and Kumar [23] studied
character segmentation. The unfixed size of handwritten characters caused problems in the segmentation.
Phukan and Borah [24] developed a system to recognize characters and vary processing stages. Features were
extracted using a feature of moments. The introduction process employed several approaches, such as
template matching, statistical techniques, structural techniques, and neural networks. Choudhary reviewed a
segmentation to automatically recognize the handwriting on a static surface. Moreover, Choudhary reviewed
some segmentation approaches: explicit, implicit, and holistic approaches. He also compared the results of
previous research that investigated word segmentation [25]. Dave [26] conducted a study using several
methods for text segmentation on images. This research assisted people to read texts on images based on the
segmentation area in computer vision. The first step was conducting the segmentation based on the retrieval
information. Then, factors that affected the segmentation process were varied. The next step was developing
segmentation levels. The last step was reviewing the employed techniques, advantages, and disadvantages of
each technique to provide suggestions to develop the next method. Bal and Saha [27] elaborated a system to
identify human characters by using the image segmentation and a rule-based system method on the slope,
baseline, and writing thickness. Durga and Deepu [28] evolved a technique to recognize handwriting using
convolution neural network algorithms on the letters i and t and produced 90% of accuracy. Jindal and Ghosh
[29] developed the segmentation of words and characters in ancient handwritten Devanagari and Maithili
documents using horizontal zoning and the accuracy obtained 97.39%.
In summary, handwritten image segmentation plays a crucial role in improving the accuracy of
handwriting-based personality analysis. Researchers have employed various techniques, including the
k-means clustering algorithm, to segment handwritten images and enhance the quality of the analysis. This
field continues to evolve with advancements in image processing and machine learning techniques.
2. METHOD
This study employed data in the form of scanned images of handwriting obtained from
graphologists. The image processing started with reading image files of handwriting. The type of these image
files was grayscale. Then, the locations of the handwriting were cropped manually. The next step was
improving the quality of the images using the spatial filter. The following step was the segmentation using
Improving the quality of handwritten image segmentation using k-means clustering… (Muhammad Munsarif)
34 ISSN: 2722-3221
the k-means clustering algorithm to separate the handwriting objects from the backgrounds. The last step was
the evaluation to determine the performance of the segmentation results. The flow diagram of the image
processing is presented in Figure 1.
3.3. Segmentation
Segmentation was done using k-means clustering algorithms and varying the k value. The displays
of binary images with various k values resulted from the segmentation are shown in Figures 4 to 7. K-means
is a clustering algorithm used in data analysis and image processing. By setting the parameter k=2, this
algorithm attempts to separate elements in handwriting into two groups based on similarity of attributes or
features. The segmentation result using k-means with k=2 will divide the elements in handwriting into two
different groups, often referred to as 'cluster 1' and 'cluster 2' or 'group 1' and 'group 2'.
When using k-means with k=3, the algorithm will aim to divide the elements in handwriting into
three groups based on their attribute or feature similarities. The segmentation result will yield three distinct
clusters, often labeled as 'cluster 1,' 'cluster 2,' and 'cluster 3' or 'group 1,' 'group 2,' and 'group 3.' This level
of segmentation can be valuable in scenarios where you need finer-grained separation of elements within
handwritten text, such as distinguishing between letters, numbers, and special characters.
With k=4 in k-means, the algorithm will work to separate elements in handwriting into four distinct
groups, each characterized by similarities in their attributes or features. The segmentation outcome will
present four separate clusters, typically identified as 'cluster 1,' 'cluster 2,' 'cluster 3,' and 'cluster 4' or 'group
1,' 'group 2,' 'group 3,' and 'group 4.' This increased level of segmentation can be advantageous when dealing
with handwritten documents containing a variety of characters or symbols, enhancing the ability to
differentiate between different types of content.
With k=4 in k-means, the algorithm will work to separate elements in handwriting into four distinct
groups, each characterized by similarities in their attributes or features. The segmentation outcome will
present four separate clusters, typically identified as 'cluster 1,' 'cluster 2,' 'cluster 3,' and 'cluster 4' or
'group 1,' 'group 2,' 'group 3,' and 'group 4.' This increased level of segmentation can be advantageous when
dealing with handwritten documents containing a variety of characters or symbols, enhancing the ability to
differentiate between different types of content.
Improving the quality of handwritten image segmentation using k-means clustering… (Muhammad Munsarif)
36 ISSN: 2722-3221
Table 1. Silhouette coefficients of images resulted from the segmentation without filters
Silhouette coefficients
No Names of images
k=2 k=3 k=4 k=5
1 text 01.jpg 0.9860 0.9702 0.9707 0.9605
2 text 02.jpg 0.9867 0.9870 0.9865 0.9842
3 text 03.jpg 0.9806 0.9751 0.9759 0.9736
4 text 04.jpg 0.9921 0.9793 0.9876 0.9778
5 text 05.jpg 0.9849 0.9771 0.9812 0.9727
Silhouette coefficients, presented in Tables 2 and 3, offer valuable insights into image segmentation.
In Table 2, the coefficients are derived from segmenting images using a 3×3 median filter, providing
evaluations for k=2, k=3, k=4, and k=5. The silhouette coefficient acts as a crucial metric, assessing both the
similarity within clusters and the distinctions between objects in different clusters. Its range, from -1 to 1,
signifies positive values for stronger intra-cluster similarity, negative values for less-than-optimal separation,
and values near 0 for cluster overlap. Essentially, it quantifies the efficacy of dividing data into two clusters
at k=2, extending to the assessment of three, four, or five clusters' performance as k increases. Table 3, on the
other hand, showcases silhouette coefficients for images segmented using a 5×5 median filter, again across
the same range of k values. It's important to note that the choice of a 3×3 or 5×5 median filter can lead to
differing segmentation characteristics, underscoring the significance of silhouette coefficient comparisons in
determining the most suitable clustering approach for specific contexts and filter size.
Silhouette coefficients of images segmented with a 5×5 median filter are shown in Table 3 for the
same k values. It should be noted that using 3×3 and 5×5 median filters can produce different segmentation
characteristics. The silhouette coefficient serves as an important metric for evaluating the extent to which
objects in a cluster are similar to each other and how well the objects in a cluster are different from others.
Silhouette coefficient values range from -1 to 1, with positive values indicating a better level of similarity
within clusters, negative values indicating less than optimal separation, and values close to 0 indicating
overlap between clusters. Thus, in essence, for the value k=2, this metric helps measure the effectiveness of
dividing the data into two clusters, while for the values k=3, k=4, and k=5, it provides information about how
well three, four, or the five clusters function in separating objects in the image.
Table 2 denote that the highest silhouette coefficients in each image were consistently observed in
the segmentation with a 3×3 median filter and a k=2. These results highlight the superior clustering
performance achieved with these specific settings, as indicated by the silhouette coefficients, which reflect
better intra-cluster similarity and more distinct inter-cluster separation. This suggests that, for the analyzed
images and segmentation task, utilizing a 3×3 median filter and selecting k=2 yielded the most optimal
clustering outcome, underscoring the importance of these parameters in image segmentation.
Table 2. Silhouette coefficients of images resulted from the segmentation with median filter of 3×3
Silhouette coefficients
No Names of images
k=2 k=3 k=4 k=5
1 text 01.jpg 0.9879 0.9741 0.9666 0.9696
2 text 02.jpg 0.9877 0.9840 0.9840 0.9801
3 text 03.jpg 0.9857 0.9754 0.9717 0.9715
4 text 04.jpg 0.9922 0.9854 0.9828 0.9784
5 text 05.jpg 0.9870 0.9748 0.9817 0.9778
Table 3. Silhouette coefficients of images resulted from the segmentation with median filter of 5×5
Silhouette coefficients
No Names of images
k=2 k=3 k=4 k=5
1 text 01.jpg 0.9899 0.9764 0.9599 0.9620
2 text 02.jpg 0.9863 0.9840 0.9822 0.9798
3 text 03.jpg 0.9881 0.9681 0.9674 0.9641
4 text 04.jpg 0.9916 0.9814 0.9785 0.9863
5 text 05.jpg 0.9870 0.9794 0.9796 0.9780
The Silhouette coefficients for image segmentation using a 3×3 mean filter and different values of
'k' in k-means clustering are shown in Table 4. The best clustering result was obtained by using a 3×3 mean
filter and selecting k=2, highlighting the significance of these parameters in image segmentation. Table 5
indicates that for the specific segmentation task using a 5×5 mean filter, the Silhouette coefficient for 'k' = 4
reached a value of 0.9744, which is notably higher than the Silhouette coefficients for other 'k' values. This
observation strongly suggests that, for this particular set of images and the chosen segmentation method,
'k' = 4 is the most suitable choice for achieving the best separation of clusters. Selecting 'k' = 4 in this context
appears to result in a superior segmentation quality, and it is likely the optimal choice for this image
segmentation task.
Table 4. Silhouette coefficients of images resulted from the segmentation with a mean filter of 3×3
Silhouette coefficients
No Names of images
k=2 k=3 k=4 k=5
1 text 01.jpg 0.9745 0.9686 0.9587 0.9499
2 text 02.jpg 0.9811 0.9772 0.9704 0.9772
3 text 03.jpg 0.9689 0.9600 0.9496 0.9580
4 text 04.jpg 0.9821 0.9779 0.9710 0.9614
5 text 05.jpg 0.9717 0.9694 0.9633 0.9662
Table 5. Silhouette coefficients of images resulted from the segmentation with a mean filter of 5×5
Silhouette coefficients
No Names of images
k=2 k=3 k=4 k=5
1 text 01.jpg 0.9643 0.9584 0.9605 0.9486
2 text 02.jpg 0.9679 0.9622 0.9708 0.9630
3 text 03.jpg 0.9480 0.9494 0.9474 0.9364
4 text 04.jpg 0.9734 0.9740 0.9744 0.9727
5 text 05.jpg 0.9614 0.9570 0.9570 0.9566
Improving the quality of handwritten image segmentation using k-means clustering… (Muhammad Munsarif)
38 ISSN: 2722-3221
4. CONCLUSION
This study investigated handwritten image segmentation using the k-means clustering algorithm.
Meanwhile, the quality of images was improved using spatial filters. The most significant segmentation
results were from the segmentation with a median filter of 3×3 and a k=2 which reach 99.22%. The results of
this study are applicable as a reference to develop an analysis system of handwritten images to identify
human characters. Further research can implement the gaussian filter to eliminate noise on handwritten
images and the deep learning method to identify the characters of writers.
REFERENCES
[1] A. H. Garoot, M. Safar, and C. Y. Suen, “A comprehensive survey on handwriting and computerized graphology,” Proceedings of
the International Conference on Document Analysis and Recognition, ICDAR, vol. 1, pp. 621–626, 2017, doi:
10.1109/ICDAR.2017.107.
[2] M. Munsarif, E. Noersasongko, P. N. Andono, A. Soeleman, Pujiono, and Muljono, “The handwriting of image segmentation
using the k-means clustering algorithm with contrast stretching and histogram equalization,” 2021 4th International Seminar on
Research of Information Technology and Intelligent Systems, ISRITI 2021, pp. 124–131, 2021, doi:
10.1109/ISRITI54043.2021.9702800.
[3] A. Chitlangia and G. Malathi, “Handwriting analysis based on histogram of oriented gradient for predicting personality traits
using SVM,” Procedia Computer Science, vol. 165, pp. 384–390, 2019, doi: 10.1016/j.procs.2020.01.034.
[4] N. Shaikh, R. Kumar, D. Tidke, R. Borude, and R. Badodekar, “Automatic predict personality based on structure of handwriting,”
in International Journal of Innovative Research in Computer and Communication Engineering, Nov. 2018, pp. 1226–1233,
[Online]. Available: http://ieeexplore.ieee.org/document/6819167/.
[5] K. Chaudhari and A. Thakkar, “Survey on handwriting-based personality trait identification,” Expert Systems with Applications,
vol. 124, pp. 282–308, 2019, doi: 10.1016/j.eswa.2019.01.028.
[6] L. M. Seng, B. B. C. Chiang, Z. A. A. Salam, G. Y. Tan, and H. T. Chai, “MNIST handwritten digit recognition with different
CNN architectures,” Journal of Applied Technology and Innovation, vol. 5, no. 1, pp. 7–10, 2021.
[7] V. Patil and H. Mathur, “A survey: Machine learning approach for personality analysis and writer identification through
handwriting,” Proceedings of the 5th International Conference on Inventive Computation Technologies, ICICT 2020, 2020, doi:
10.1109/ICICT48043.2020.9112449.
[8] N. M. Zaitoun and M. J. Aqel, “Survey on image segmentation techniques,” Procedia Computer Science, vol. 65, pp. 797–806,
2015, doi: 10.1016/j.procs.2015.09.027.
[9] D. Kaur and Y. Kaur, “Various image segmentation techniques: a review,” International Journal of Computer Science and Mobile
Computing, vol. 3, no. 5, pp. 809–814, 2014, [Online]. Available: www.ijcsmc.com.
[10] I. Patel and S. Patel, “Analysis of various image segmentation techniques for flower images deep learning for object detection
view project analysis of various image segmentation techniques for flower images,” Journal of Applied Science and
Computations, vol. 6, no. 2, pp. 1936–1943, 2019, [Online]. Available: https://www.researchgate.net/publication/344249453.
[11] S. Khanmohammadi, N. Adibeig, and S. Shanehbandy, “An improved overlapping k-means clustering method for medical
applications,” Expert Systems with Applications, vol. 67, pp. 12–18, 2017, doi: 10.1016/j.eswa.2016.09.025.
[12] N. Tokas, S. Karkra, and K. Pandey, “Comparison of digital image segmentation techniques-a research review,” International
Journal of Computer Science and Mobile Computing, vol. 5, no. 5, pp. 215–220, 2016, [Online]. Available: www.ijcsmc.com.
[13] H. Guo, J. Ma, and Z. Li, “Active semi-supervised K-means clustering based on silhouette coefficient,” Advances in Intelligent
Systems and Computing, vol. 885, pp. 202–209, 2019, doi: 10.1007/978-3-030-02804-6_27.
[14] A. Taneja, P. Ranjan, and A. Ujjlayan, “A performance study of image segmentation techniques,” 2015 4th International
Conference on Reliability, Infocom Technologies and Optimization: Trends and Future Directions, ICRITO 2015, 2015, doi:
10.1109/ICRITO.2015.7359305.
[15] H. Belyadi and A. Haghighat, “Unsupervised machine learning: clustering algorithms,” Machine Learning Guide for Oil and Gas
Using Python, pp. 125–168, 2021, doi: 10.1016/b978-0-12-821929-4.00002-0.
[16] K. Deeparani and P. Sudhakar, “Efficient image segmentation and implementation of K-means clustering,” Materials Today:
Proceedings, vol. 45, pp. 8076–8079, 2021, doi: 10.1016/j.matpr.2021.01.154.
[17] P. Shi, X. Fan, J. Ni, and G. Wang, “A detection and classification approach for underwater dam cracks,” Structural Health
Monitoring, vol. 15, no. 5, pp. 541–554, 2016, doi: 10.1177/1475921716651039.
[18] N. Dhanachandra, K. Manglem, and Y. J. Chanu, “Image segmentation using k-means clustering algorithm and subtractive
clustering algorithm,” Procedia Computer Science, vol. 54, pp. 764–771, 2015, doi: 10.1016/j.procs.2015.06.090.
[19] M. Brodowska, “Oversegmentation methods for character segmentation in off-line cursive handwritten word recognition–an
overview,” Schedae Informaticae, vol. 20, no. 20, pp. 43–65, 2011, [Online]. Available:
http://www.wuj.pl/UserFiles/File/Schedae 20 N/Schedae Informaticae_20_2p.pdf.
[20] R. KumarNath and M. Rastogi, “Improving various offline techniques used for handwritten character recognition: a review,”
International Journal of Computer Applications, vol. 49, no. 18, pp. 11–17, 2012, doi: 10.5120/7726-1136.
[21] A. Choudhary, R. Rishi, and S. Ahlawat, “New character segmentation approach for off-line cursive handwritten words,”
Procedia Computer Science, vol. 17, pp. 88–95, 2013, doi: 10.1016/j.procs.2013.05.013.
[22] A. Choudhary, R. Rishi, and S. Ahlawat, “A new approach to detect and extract characters from off-line printed images and text,”
Procedia Computer Science, vol. 17, pp. 434–440, 2013, doi: 10.1016/j.procs.2013.05.056.
[23] V. Rani and P. Kumar, “Problems of character segmentation in handwritten text documents written in Devnagari Script,”
International Journal of Advanced Research in Computer Engineering & Technology, vol. 2, no. 3, pp. 1026–1029, 2013.
[24] A. P. and M. Borah, “A survey paper on character recognition focusing on offline character recognition,” International Journl of
computer Engineering and Applications, vol. 6, no. 1, pp. 51–60, 2014.
[25] A. Choudhary, “A review of various character segmentation techniques for cursive handwritten words recognition,” International
Journal of Information & Computation Technology, vol. 4, no. 6, pp. 559–564, 2014, [Online]. Available:
http://www.irphouse.com.
[26] N. Dave, “Segmentation methods for hand written character recognition,” International Journal of Signal Processing, Image
Processing and Pattern Recognition, vol. 8, no. 4, pp. 155–164, 2015, doi: 10.14257/ijsip.2015.8.4.14.
[27] A. Bal and R. Saha, “An improved method for handwritten document analysis using segmentation, baseline recognition and
writing pressure detection,” Procedia Computer Science, vol. 93, pp. 403–415, 2016, doi: 10.1016/j.eswa.2023.120127.
[28] L. Durga and R. Deepu, “Ensemble deep learning to classify specific types of t and i patterns in graphology,” Global Transitions
Proceedings, vol. 2, no. 2, pp. 287–293, 2021, doi: 10.1016/j.gltp.2021.08.025.
[29] A. Jindal and R. Ghosh, “Word and character segmentation in ancient handwritten documents in Devanagari and Maithili scripts
using horizontal zoning,” Expert Systems with Applications, vol. 225, 2023, doi: 10.1016/j.eswa.2023.120127.
BIOGRAPHIES OF AUTHORS
Improving the quality of handwritten image segmentation using k-means clustering… (Muhammad Munsarif)