This paper introduces a new method to medical image segmentation using a reinforcement learning scheme. We use this novel idea as an effective way to optimally find the appropriate local thresholding and structuring element values and segment the prostate in ultrasound images. Reinforcement learning agent uses an ultrasound image and its manually segmented version and takes some actions (i.e., different thresholding and structuring element values) to change the environment (the quality of segmented image). The agent is provided with a scalar reinforcement signal determined objectively. The agent uses these objective reward/punishment to explore/exploit the solution space. The values obtained using this way can be used as valuable knowledge to fill a Q-matrix. The reinforcement learning agent can use this knowledge for similar ultrasound images as well. The results demonstrate high potential for applying reinforcement learning in the field of medical image segmentation.