Le Activity Sieben

This activity is called Image segmentation. We are to segment a region of interest (ROI) from the original image using two different ways: parametric and non-parametric segmentation. For this activity, I chose to use a picture of my favorite wrestler to segment.

segment

Figure 1. Image of my favorite wrestler, John Cena.

Doing probability distribution estimation, I used imageJ to take different patches for my ROI. As seen from the following figure, I simply attempted to segment his skin from his armbands and his bling. One patch I took was a small area on his left shoulder, another patch that I took was from his chest area which included a part of his hand.

cena3

Figure 2. Using ImageJ to take patches of his skin as my ROI.

In the next Figure, I show the results of image segmentation using the two patches. The image on the left shows a bright area around his left shoulder but dark everywhere else. This is because the ROI taken is small and it can be seen that the ROI taken is monochromatic that it will not take into consideration shadows and lighting effects on the skin of John Cena. On the other hand, the segmented image on the right uses a ROI with more detail (includes shadow gradients and lighting effects) which will appropriately adjust the mean and standard deviation for segmentation. With a larger range of values that can be accepted, the segmented image now properly shows the skin area of John Cena.

cena4

Figure 3. (left) Segmentation using a small patch on the shoulder, (right) segmentation using a patch which includes a part of his hand.

For my going beyond, I present HulkCena and BarneyCena. They are created by thresholding the resulting values of segmentation, for which when a probability value of the pixel is above the threshold, I set the value of the RGB channel to maximum depending on which color I want to achieve. Lastly I will use the segmented image as a mask to simulate the shadow effects on HulkCena and BarneyCena.

              hulkcena     barneycena

Figure 4. HulkCena (left) and BarneyCena (right) made by using the segmented image as a mask to a certain color value.

For this activity, I will give myself a 8. Though there is lacking output, I compensate it with a going beyond output. Acknowledgements to Gio-sama for guiding me through this activity. Here is the python code used for this activity.

# -*- coding: utf-8 -*-

“””

Created on Wed Oct 14 11:00:41 2015

@author: jesli

“””

def prob(r,mean,std):

return np.exp(-(r-mean)**2/(2*std**2))/(std*(np.pi)**0.5)

import numpy as np

import matplotlib.pyplot as plt

import Image as im

from scipy import misc

import matplotlib.cm as cm

seg1=np.array(im.open(‘segment1.png’))

#seg1=np.array(double(seg1))

cena=np.asarray(im.open(‘segment.png’))

#cena=np.array(double(cena))

Rseg1=seg1[:,:,0]

Gseg1=seg1[:,:,1]

Bseg1=seg1[:,:,2]

I=Rseg1+Gseg1+Bseg1

r=Rseg1/I

g=Gseg1/I

rmean=np.mean(r)

gmean=np.mean(g)

rstd=np.std(r)

gstd=np.std(g)

cenaR=cena[:,:,0]

cenaG=cena[:,:,1]

cenaB=cena[:,:,2]

cenaI=cenaR+cenaG+cenaB

for i in range(len(cenaI)):

for j in range(len(cenaI[0])):

if cenaI[i][j]==0:

cenaI[i][j]=999999999999999

cenar=cenaR/cenaI

cenag=cenaG/cenaI

cenaprobr=prob(cenar,rmean,rstd)

cenaprobg=prob(cenag,gmean,gstd)

product=(cenaprobr*cenaprobg)

product/=np.max(product)

#ilist=[]

#jlist=[]

#for i in range(len(product)):

# for j in range(len(product[0])):

# if product[i][j]>0.5:

## cenaR[i][j]=0

## cenaB[i][j]=0

## cenaG[i][j]=int(product[i][j]*255)

# cenaG[i][j]=0

# cenaR[i][j]=int(product[i][j]*255)

# cenaB[i][j]=int(product[i][j]*255)

#

#hulkcena=cena

#hulkcena[:,:,0]=cenaR

#hulkcena[:,:,1]=cenaG

#hulkcena[:,:,2]=cenaB

#segment=misc.imread(‘segment2.png’)

plt.matshow(product,cmap=cm.gray)

#I=R+G+B

#r=R/I

#g=G/I

#b=B/I

Leave a comment