this procedure could be changed to extract the image directly