<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def background_model(self, ignore_black=True, use_hsv=False, scale=8):
 """Creates a background model for the given image. The background color is given by the modes of each channel's histogram. Parameters ignore_black : bool If True, the zero pixels will be ignored when computing the background model. use_hsv : bool If True, image will be converted to HSV for background model generation. scale : int Size of background histogram bins -- there will be BINARY_IM_MAX_VAL/size bins in the color histogram for each channel. Returns ------- A list containing the red, green, and blue channel modes of the background. """

        # hsv color
        data = self.data
        if use_hsv:
            pil_im = PImage.fromarray(self._data)
            pil_im = pil_im.convert('HSV')
            data = np.asarray(pil_im)

        # find the black pixels
        nonblack_pixels = np.where(np.sum(self.data, axis=2) > 0)
        r_data = self.r_data
        g_data = self.g_data
        b_data = self.b_data
        if ignore_black:
            r_data = r_data[nonblack_pixels[0], nonblack_pixels[1]]
            g_data = g_data[nonblack_pixels[0], nonblack_pixels[1]]
            b_data = b_data[nonblack_pixels[0], nonblack_pixels[1]]

        # generate histograms for each channel
        bounds = (0, np.iinfo(np.uint8).max + 1)
        num_bins = bounds[1] / scale
        r_hist, _ = np.histogram(r_data, bins=num_bins, range=bounds)
        g_hist, _ = np.histogram(g_data, bins=num_bins, range=bounds)
        b_hist, _ = np.histogram(b_data, bins=num_bins, range=bounds)
        hists = (r_hist, g_hist, b_hist)

        # find the thesholds as the modes of the image
        modes = [0 for i in range(self.channels)]
        for i in range(self.channels):
            modes[i] = scale * np.argmax(hists[i])

        return modes