<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a id="top"></a>
Compute Items Features
First
Step1:  Compute and Save<a id="compute"></a>
Issues
Step2:  Statistics???<a id="statistics"></a>
Step3:  Plot File<a id="plot"></a>
Step4:  Plot All Items
Step5:  Computing Test<a id="test"></a>
Step6:  Compute and Plot All Items
<ASSISTANT_TASK:>
Python Code:
import json
from utils import load_items
with open('parameters.json', 'r') as infile:
    params = json.load(infile)
RESIZE_X = params['resize']['x']
RESIZE_Y = params['resize']['y']
ITEM_FOLDER = params['item_folder']
items = load_items(ITEM_FOLDER)
Explanation: <a id="top"></a>
Compute Items Features
First:
* Load Parameters and Items
Then choose one operation:
* Compute and Save
* Statistics
* Plot Item Files
* Computing Test
Load Parameters and Items<a id="load"></a>
End of explanation
import cv2, glob
from utils import imread_rgb, imread_gray, compute_colors
def worker(item):
    folder = ITEM_FOLDER + '/' + item + '/'
    files = glob.glob(folder + '*.png')
    for filename in files:
        image_RGB = imread_rgb(filename)
        if not image_RGB is None:
            image_RGB = cv2.resize(image_RGB,(RESIZE_X,RESIZE_Y))
            file_mask = filename[:-4] + '_mask.pgm'
            mask = imread_gray(file_mask)
            hist, cc = compute_colors(image_RGB, mask)
            dominant_colors = {'hist': hist,
                               'cluster_centers': map(lambda t: list(t), cc)}
            with open(filename[:-4] + '_dc.json', 'w') as outfile:
                json.dump(dominant_colors, outfile)
%%time
from multiprocessing import Pool
print('Computing Dominant colors of images')
print('* resized to %d x %d' % (RESIZE_X,RESIZE_Y))
print('* LAB space')
print('* KMeans')
#print('* MiniBatchKMeans')
pool_size = 6
pool = Pool(pool_size)
result = []
for item in items:
    result.append( pool.apply_async(worker, (item,)) )
pool.close()
pool.join()
for r in result:
     r.get()
Explanation: Compute and Save<a id="compute"></a>
Issues:
* remove black color from transparent items, e.g.:
  * poland_spring
  * ...
End of explanation
import glob
from utils import ...
item_view = []
VVV = []
for item in items:
    folder = ITEM_FOLDER + '/' + item + '/'
    files = glob.glob(folder + '*_XXX.YYY')
    for filename in files:
        ...
        item_view.append(filename)
        VVV.append(len(des))
from matplotlib import pyplot as plt
%matplotlib inline
plt.hist(VVV,bins=60);
[(ns, str(iv.split('/')[-1][:-9])) for ns, iv in sorted(zip(VVV,item_view), reverse=True) if ns>2000]
[(ns, str(iv.split('/')[-1][:-9])) for ns, iv in sorted(zip(VVV,item_view), reverse=True) if ns<50]
Explanation: Statistics???<a id="statistics"></a>
End of explanation
from matplotlib import pyplot as plt
%matplotlib inline
import cv2, numpy as np
from ipywidgets import interact
from utils import imread_rgb, plot_colors
def load_and_plot(item,view):
    try:
        prefix = ITEM_FOLDER + '/' + item + '/' + item + '_' + view
        filename = prefix + '.png'
        image_RGB = imread_rgb(filename)
        if not image_RGB is None:
            with open(filename[:-4] + '_dc.json', 'r') as infile:
                dc = json.load(infile)
            hist = dc['hist']
            cc = dc['cluster_centers']
            bar = plot_colors(hist, cc)
            plt.subplot(121); plt.imshow(image_RGB); plt.axis('off');
            plt.subplot(122); plt.imshow(bar); plt.axis('off');
    except (IOError, OSError):
        print('File not found')
views = ['top_01','top-side_01','top-side_02','bottom_01','bottom-side_01','bottom-side_02']
interact(load_and_plot,item=items,view=views);
Explanation: Plot File<a id="plot"></a>
End of explanation
for item in items:
    for view in views:
        print(item + '_' + view)
        load_and_plot(item,view)
        plt.show()
Explanation: Plot All Items
End of explanation
from matplotlib import pyplot as plt
%matplotlib inline
import cv2, numpy as np
from ipywidgets import interact
from utils import imread_rgb, imread_gray, compute_colors, plot_colors
def compute_and_plot(item,view):
    prefix = ITEM_FOLDER + '/' + item + '/' + item + '_' + view
    filename = prefix + '.png'
    image_RGB = imread_rgb(filename)
    if not image_RGB is None:
        image_RGB = cv2.resize(image_RGB,(RESIZE_X,RESIZE_Y))
        filename = prefix + '_mask.pgm'
        mask = imread_gray(filename)
        plt.subplot(121); plt.imshow(image_RGB); plt.axis('off');
        hist, cc = compute_colors(image_RGB, mask)
        bar = plot_colors(hist, cc)
        plt.subplot(122); plt.imshow(bar); plt.axis('off'); plt.title(item + '_' + view);
views = ['top_01','top-side_01','top-side_02','bottom_01','bottom-side_01','bottom-side_02']
interact(compute_and_plot,item=items,view=views);
Explanation: Computing Test<a id="test"></a>
End of explanation
for item in items:
    for view in views:
        print(item + '_' + view)
        plot(item,view)
        plt.show()
Explanation: Compute and Plot All Items
End of explanation
<END_TASK>