Commits

Miroslav Shubernetskiy committed 493b80e

Added docs to hw4

Comments (0)

Files changed (4)

docs/hw4/index.rst

+Homework 4
+==========
+
+Problem 1
+---------
+
+This problem is to implement 1d signal re-sampler which can use various kernels.
+
+.. automodule:: hw4.prob1
+    :members:
+
+
+Problem 2
+---------
+
+This problem is to implement 2d signal re-sampler which can resize images using
+different kernels.
+
+.. automodule:: hw4.prob2
+    :members:
    hw1/index
    hw2/index
    hw3/index
+   hw4/index
 
 
 
 """
+Usage
+-----
 
+:input-path:
+    Path to the input comma separated file where the input numbers are stored
+:output-path:
+    Path to where the output of the re-sampling should be stored
+:output-len:
+    The quantity of samples which should be sampled
+:kernel:
+    The id of the kernel to be used for re-sampling. Some kernel values require an
+    additional parameter, ``param``.
+
+    :0: Nearest neighbor
+    :1: Linear
+    :2: Cubic
+    :3: Hann Window
+    :4: Hamming Window
+    :5: Lanczos
+:param:
+    The additional parameter for the kernel. For most kernels will define some sort of
+    free variable.
+
+Example
+-------
+
+::
+
+    $ python prob1.py in.txt out.txt 64 3 4
 """
 
 import sys, os, numpy, math
 
 
 class Resize1D:
+    """
+    Class for applying 1d re-sampling to the input numbers.
+
+    Attributes
+    ----------
+    method : def
+        Pointer to the function which should be used for weight in re-sampling
+    method_base : def, optional
+        Optional. Some filter functions require two steps. For example first computing the window
+        function and second multiplying the window by some function. This attribute points to the
+        base function (where window is computed) if one is applicable
+    method_name : str
+        The name of the re-sampling method
+    fwidth : int
+        The width of the filter
+    fscale : float
+        The scale of the filter. When image is minified, the filter has to be wider it's normal width.
+        This scale determined how much wider and inversely proportional of the weight ratio.
+    enable_show : bool
+        If the graph of the input vs output should be drawn during computation
+    """
     method = None
     method_base = None
     method_name = ''
     fscale = 1
     enable_show = False
 
-    def __init__(self):
-        pass
+    def nearestNeighborFilter(self):
+        """
+        Filter for computing nearest neighbor value
 
-    def nearestNeighborFilter(self):
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the weight value
+        """
         def f(x):
             if -0.5 < x <= 0.5:
                 return 1
         return f
 
     def linearInterpolationFilter(self):
+        """
+        Filter for computing linear weight value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the weight value
+        """
         def f(x):
             x = abs(x)
             if x < 1:
         return f
 
     def cubicConvolutionFilter(self, param):
+        """
+        Filter for computing cubic convolution weight
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the weight value
+        """
         def f(x):
             x = abs(x)
             x2 = x ** 2
         return f
 
     def hannWindowFilterBase(self, param):
+        """
+        Filter for computing hann window value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the window value
+        """
         def f(x):
             x = abs(x)
             if x < param:
         return memoize(f)
 
     def hannWindowFilter(self, param):
+        """
+        Filter for computing hann window filter weight value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the weight value
+        """
         g = self.hannWindowFilterBase(param)
 
         def f(x):
 
 
     def hammingWindowFilterBase(self, param):
+        """
+        Filter for computing hamming window value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the window value
+        """
+
         def f(x):
             x = abs(x)
             if x < param:
         return memoize(f)
 
     def hammingWindowFilter(self, param):
+        """
+        Filter for computing hamming window filter weight value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the weight value
+        """
         g = self.hammingWindowFilterBase(param)
 
         def f(x):
 
 
     def lanczosWindowFilterBase(self, param):
+        """
+        Filter for computing lanczos window value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the window value
+        """
         def f(x):
             x = abs(x)
             if x < param:
         return memoize(f)
 
     def lanczosWindowFilter(self, param):
+        """
+        Filter for computing lanczos window filter weight value
+
+        Returns
+        -------
+        f : def
+            A function which given ``x``, computes the weight value
+        """
         g = self.lanczosWindowFilterBase(param)
 
         def f(x):
         return memoize(f)
 
     def setResizeMethod(self, id, param=None):
+        """
+        Set what method should be used for re-sampling the input signal.
+
+        Parameters
+        ----------
+        id : int
+            The id of the kernel
+        param : float
+            Any additional parameter the kernel might need.
+        """
         if id == 0:
             self.method = self.nearestNeighborFilter()
             self.method_name = 'nearest'
             raise ValueError('Unsupported filter method')
 
     def plotFilterAndData(self, ori_data, data):
+        """
+        For debug purposes, display the graph of how the input and output signals relate to each other.
+
+        Parameters
+        ----------
+        ori_data : list
+            The original input signal array of values
+        data : list
+            The list of values which were computed as a result of the re-sampling
+        """
         global figure_counter
         figure_counter += 1
         plt.figure(figure_counter)
             plt.show()
 
     def show(self, enable=True):
+        """
+        Show the available plots. Useful in debugging and when multiple plots have to be displayed
+
+        Parameters
+        ----------
+        enable : bool
+            If the plots should be displayed
+        """
         self.enable_show = enable
         if enable:
             self.enable_show = enable
 
 
     def resize(self, data, new_n):
+        """
+        Given a set of data, re-sample the data to have ``new_n`` samples.
+
+        Parameters
+        ----------
+        data : list
+            The list of signal values which should be re-sampled
+        new_n : int
+            The number of samples which should be present in the output
+        """
         if type(data) != numpy.ndarray:
             data = numpy.array(data)
         ori_n = len(data)
 """
+Usage
+-----
 
+:input-image-path:
+    Path to the input image
+:output-image-path:
+    Path to where re resized image should be stored
+:new-w:
+    The new width of the image
+:new-h:
+    The new height of the image
+:kernel:
+    The id of the kernel to be used for re-sampling. Some kernel values require an
+    additional parameter, ``param``.
+
+    :0: Nearest neighbor
+    :1: Linear
+    :2: Cubic
+    :3: Hann Window
+    :4: Hamming Window
+    :5: Lanczos
+:param:
+    The additional parameter for the kernel. For most kernels will define some sort of
+    free variable.
+
+Example
+-------
+
+::
+
+    $ python prob1.py mandrill.png output.png 64 64 3 4
 """
 import sys, os, numpy, Image
 from prob1 import Resize1D
 from base.ip import *
 
 class Resize2D(IP_Image):
-    resizemethod = None
+    """
+    Class for applying 2d re-sampling to the input image.
 
-    def __init__(self):
-        self.resizemethod = Resize1D()
+    Inherits from ``IP_Image``.
+
+    Attributes
+    ----------
+    resizemethod : Resize1D
+        The pointer to the resize1D class which will be used for resizing
+    """
+    resizemethod = Resize1D()
 
     def setResizeMethod(self, kernel, param):
+        """
+        Se the resize method. Same as ``Resize1D.setResizeMethod``.
+        """
         self.resizemethod.setResizeMethod(kernel, param)
 
     def resize(self, width, height):
+        """
+        Resize the image to the given widht and height
+
+        Parameters
+        ----------
+        width : int
+            The new width
+        height : int
+            The new height
+        """
         size = self.img.size
         data = numpy.asarray(self.img)
         total = width * height