Sunspots are solar features located in active regions of the Sun, whose number is an indicator of the Sun's magnetic activity. Therefore accurate detection and classification of sunspots are fundamental for the elaboration of solar activity indices such as the Wolf number. However, irregularities in the shape of the sunspots and their variable intensity and contrast with the surroundings, make their automated detection from digital images difficult. Here, we present a morphological tool that has allowed us to construct a simple and automatic procedure to treat digital photographs obtained from a solar telescope, and to extract the main features of sunspots. Comparing the solar indices computed with our algorithm against those obtained with the previous method exhibit an obvious improvement. A favorable comparison of the Wolf sunspot number time series obtained with our methodology and from other reference observatories is also presented. Finally, we compare our sunspot and group detection to that of other observatories.