DNA analysis is currently becoming very important to diagnose diseases. One of the approaches is using microarray technology. A microarray is made up of thousands of molecules that are placed in a specific location called spots. Each spot contains multiple identical strands of DNA, which identify one gene. The purpose of this paper is classified the gene in microarray data. The proposed method consists of four major processes. The first is preprocessing microarray images. The second is segmentation of foreground and background in microarray image. The third is calculation of gene expression, then normalized the segmented microarray image. The fourth, k-Nearest Neighbor based Particle Swarm Optimization is conducted to select and classify the normalized gene that represented cancer and healthy condition. The results show that the proposed system is suitable for detecting various diseases. The effectiveness of this system is demonstrated by the usage of a few gene expression datasets. The average accuracy of proposed system in breast cancer, ALL, DLBCL datasets is 100%, 96% and 82.3% respectively.