The fast development in worldwide technology makes it essential for us to find solutions for some challenging problems; one of these is the recognition of the important details from images. Text recognition is a process that converts the text that any image contains to something that is recognizable for our modern devices e.g., our smart phones. In this paper an efficient algorithm for the detection of text from an image is proposed. This methodology includes the application of a powerful segmentation method that labels the letters in the image very efficiently, and then the mean of the coordinates of each letter within the image is used after the application of the segmentation method in order to sort the letters correctly, moreover, the algorithm includes the introduction of a new line detection method based on the mean of the labels, and finally some modifications on the work of the autoencoder neural network is proposed in this paper. The transformation of the text in the image to text document is achieved with high accurate result; the results show a complete recognition of the text in wide varieties of images. Examples of the application of this algorithm are for the detection of the text in image with many lines, road sign images and car plate number recognition are shown in this paper.