[画像を、別の画像に、重ね塗りする] , Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

Python(パイソン) プログラム作ってみた インデックス へ

-----

2024.10.13 presented in [note] ( //note.com/runningWater/ )

----------
これ以降に記述されている内容は、このようなコンピューター・プログラムを制作した、というような事を、ただ、述べているに過ぎない。

以下の記述を読んだ人が、それを単に参考にする、というのであれば、問題は無いと、思われる。

しかし、記述されている内容に沿って、その人が、そこに記されているのと同様の制作や作業を行った際に、その制作、作業、コンピューターの作動の結果、使用されたコンピューター等、様々な方面において、何らかの問題が発生しない、という保証は、全くない。

その制作、作業、コンピューターの作動の結果、その人や、その人が所属している組織、その人が使用した様々な機器、インフラストラクチャー等の、身の上にどのような事が起ころうとも、私は一切、責任を負わない。

このプログラムは、Python(パイソン) 言語を使って、記述されている。

----------
2 どのようなものを作ったのか

以下、使用例で、説明する。

以下に説明するプログラムを使って、

下記の、 [Fig 1] の画像、 [Fig 2] の画像、[Fig 3]の画像より、下記の、 [Fig 4]の画像、[Fig 5]の画像、[Fig 6]の画像、が、作成された。

Fig 1
Fig 2
Fig 3
Fig 4
Fig 5
Fig 6

[Fig 4]画像は、[Fig 1] 画像を、[Fig 3] 画像の上に、回転した後に、重ね塗りしたような内容になっている。

[Fig 5]画像は、
 [Fig 2]画像中の黄色に塗られている部分
 に対応する、[Fig 1] 画像の部分のみを、
 [Fig 3] 画像の上に、回転しないで、重ね塗りしたような内容になっている。

[Fig 6]画像は、
 [Fig 2]画像中の緑色に塗られている部分
 に対応する、[Fig 1] 画像の部分のみを、
 [Fig 3] 画像の上に、回転しないで、重ね塗りしたような内容になっている。

上記の説明中、
 「回転」に関しては、後述の、[do_rotation]パラメーター に関する説明の中で、述べる。
 「黄色に塗られている部分に対応する」、「緑色に塗られている部分に対応する]に関しては、後述の、[use_or_not_PatternImageData]パラメーター に関する説明の中で、述べる。

以降、下記のような用語を用いる。

 [コピー元・画像]  [Fig 1] に示されている画像
 [コピーパターン・画像]  [Fig 2] に示されている画像
 [挿入される側・ソース画像]  [Fig 3] に示されている画像
 [挿入される側・生成画像]   [Fig 4] 、 [Fig 5] 、[Fig 6] に示されている画像
 
この処理においては、以下のようなパラメーターを、調整できるようになっている。

use_or_not_PatternImageData
 [コピーパターン・画像]を使用して、コピーする範囲を限定するか、否か
directed_x_and_y_on_PatternImageData
 [コピーパターン・画像]中の、指定位置
   use_or_not_PatternImageData = "Y" と、指定した場合には、
   [コピーパターン・画像]中の、ここに指定されている、xy座標の位置にあるピクセルの色と、
   同じ色を持つ、 [コピーパターン・画像]中の部分の範囲内に、
  [コピー元・画像]から、[挿入される側・生成画像]への、コピー対象となる範囲が、限定される
 
color_copying
 [コピー元・画像]中のピクセルのうち、ここで指定された色の範囲を持つものだけが、コピー対象となる
CopySource_From_and_To_xy
 [コピー元・画像]中のピクセルのうち、ここで指定された位置(XY座標)の範囲を持つものだけが、コピー対象となる
scale_rate_CopySource_to_InsertedSide
 [コピー元・画像] から [挿入される側・生成画像] への出力の際の、縮尺を、指定する
color_rate_CopySource_to_InsertedSide
 [コピー元・画像] から [挿入される側・生成画像] への出力の際の、
   [コピー元・画像] と [挿入される側・ソース画像] との(色の)混合比率を、指定する
Center_xy_of_inserting_on_InsertedSide_Source
 [挿入される側・生成画像]の中の、挿入対象となる範囲の中心位置(XY座標)を、指定する
 
do_rotation
 [コピー元・画像] から、[挿入される側・生成画像]へ、コピーする際に、回転を行った後のイメージを、コピーするか、否か
rotation_degree_of_inserting_on_InsertedSide_Source
 do_rotation = "Y" と、指定した場合には、ここで指定された角度分だけ、回転した後に、コピーする

----------

このプログラムは、適宜、下記で説明されているモジュールを、使用している。

[画像処理, OpenCV2 使用] を 行う, 機能追加版, 多角形(内部ぬりつぶし)描画機能を追加] , Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

Python(パイソン) ,ソースプログラムリスト あり ,プログラム作ってみた ,[エラー処理] を 行う

----------
3 構成

このモジュール群は、以下のモジュールから、構成されている。

 [ CopyAndInsertImageDataV2 ]
 [ TestCopyAndInsertImageDataV2 ]

以降に、これらのモジュールの内容を、記す。

----------
4 [ CopyAndInsertImageDataV2 ]

ファイル名 [ CopyAndInsertImageDataV2.py ]

----------


import  math

import  ImageDataTwoDimensionHandlingV3

#===========================================
class  CopyAndInsertImageDataV2  :

    CV_CLASS_NAME = "CopyAndInsertImageDataV2"

    #------------------------------------------------------------
        # definition of constructer

    def __init__( self  ):

        methode_name = "constructer"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

                                      #[ 0 ] , ImageData CopySource
                                      #[ 1 ] , ImageData CopySource PatternImageData
                                      #[ 2 ] , ImageData InsertedSide_Source
                                      #[ 3 ] , ImageData InsertedSide_Generated
        self.iv_list_ImageDataTwoDimensionHandling = [ "" , "" , "" , "" ]

        self.iv_width_of_ImageData_InsertedSide_Generated = 0
        self.iv_height_of_ImageData_InsertedSide_Generated = 0

        print( "==================================" )
        print( "Exit from , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

        return

#==============================================
    def  construct_ImageData ( self   ,  arg_index  )  :

        methode_name = "construct_ImageData"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_index = " , arg_index )
        print( "==================================" )

        self.iv_list_ImageDataTwoDimensionHandling [ arg_index ] = \
              ImageDataTwoDimensionHandlingV3   \
                  .ImageDataTwoDimensionHandlingV3 ( \
                         CopyAndInsertImageDataV2.CV_CLASS_NAME
                       , methode_name
                                                                     )

        print( "==================================" )
        print( "Exit from , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

#--------------------------------------------
    def  load_ImageData ( self  \
                        ,   arg_index
                        ,   arg_abs_path_of_ImageData
                                    )  :

        methode_name = "load_ImageData"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_index = " , arg_index )
        print ( "arg_abs_path_of_ImageData = "
                         , arg_abs_path_of_ImageData )
        print( "==================================" )

        self.iv_list_ImageDataTwoDimensionHandling [ arg_index ]  \
             .load_image_data ( \
                      CopyAndInsertImageDataV2.CV_CLASS_NAME
                    , methode_name
                    , arg_abs_path_of_ImageData
                                         )

        print( "==================================" )
        print( "Exit from , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

#--------------------------------------------
    def  set_ImageData ( self  \
                        ,   arg_index
                        ,   arg_ins_ImageDataTwoDimensionHandling
                                  )  :

        methode_name = "set_ImageData"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_index = " , arg_index )
        print( "==================================" )

        self.iv_list_ImageDataTwoDimensionHandling [ arg_index ]  \
                          = arg_ins_ImageDataTwoDimensionHandling

        print( "==================================" )
        print( "Exit from , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

#--------------------------------------------
    def  get_ImageData ( self  \
                        ,   arg_index
                                   )  :

        methode_name = "get_ImageData"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_index = " , arg_index )
        print( "==================================" )

        print( "==================================" )
        print( "Exit from , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

        return  self.iv_list_ImageDataTwoDimensionHandling [ arg_index ]

#=============================================
    def  write_InsertedSide_Generated_ImageData ( self  \
                        ,   arg_abs_path_of_InsertedSide_Generated_ImageData
                                                                          )  :

        methode_name = "write_InsertedSide_Generated_ImageData"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

        self.iv_list_ImageDataTwoDimensionHandling [ 3 ]  \
              .write_loaded_image_data_to_directed_path ( \
                         CopyAndInsertImageDataV2.CV_CLASS_NAME
                       , methode_name
                       , arg_abs_path_of_InsertedSide_Generated_ImageData
                                                                                )

        print( "==================================" )
        print( "Exit from , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print( "==================================" )

#=================================
    def  copy_and_insert_ImageData (   self   \
                        ,   arg_use_or_not_PatternImageData
                        ,   arg_list_directed_x_and_y_on_PatternImageData
                         ,  arg_list_color_copying
                         ,  arg_list_CopySource_From_and_To_xy
                         ,  arg_scale_rate_CopySource_to_InsertedSide
                         ,  arg_color_rate_CopySource_to_InsertedSide
                         ,  arg_list_Center_xy_of_inserting_on_InsertedSide_Source
                         ,  arg_do_rotation
                         ,  arg_rotation_degree_of_inserting_on_InsertedSide_Source
                                                      )  :

        methode_name = "copy_and_insert_ImageData"

        print( "==================================" )
        print( "Enter into , Class = "
                   + CopyAndInsertImageDataV2.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_use_or_not_PatternImageData = "  \
                           , arg_use_or_not_PatternImageData )
        print ( "arg_list_directed_x_and_y_on_PatternImageData = "  \
                           , arg_list_directed_x_and_y_on_PatternImageData )
        print ( "arg_list_color_copying = "  \
                           , arg_list_color_copying )
        print( "==================================" )

        list_color_of_pixel_directed_x_and_y_on_PatternImageData = [ 0 , 0 , 0 ]
                        #---------------------
        if (  arg_use_or_not_PatternImageData == "Y" ) :
                             #use PatternImageData
            list_color_of_pixel_directed_x_and_y_on_PatternImageData =   \
                self.iv_list_ImageDataTwoDimensionHandling [ 1 ]   \
                        .get_data_of_one_pixel ( \
                                CopyAndInsertImageDataV2.CV_CLASS_NAME
                             ,  methode_name
                              # in the commonly used mathematical XY cordinates
                             ,  arg_list_directed_x_and_y_on_PatternImageData [ 0 ]
                             ,  arg_list_directed_x_and_y_on_PatternImageData [ 1 ]
                                                          )

            print ( "==================================" )
            print ( " Class = "  + CopyAndInsertImageDataV2.CV_CLASS_NAME
                          + " , methode = " + methode_name )
            print ( "list_color_of_pixel_directed_x_and_y_on_PatternImageData = " \
                        , list_color_of_pixel_directed_x_and_y_on_PatternImageData )
            print ( "==================================" )

         #-----------------------------------------------------------------
        list_center_xy_of_copying_area = [  \
                                     # from x
                      (  arg_list_CopySource_From_and_To_xy [ 0 ] [ 0 ]   \
                         +                                                                      \
                                     # to x
                         arg_list_CopySource_From_and_To_xy [ 1 ] [ 0 ]   \
                               ) / 2.0                                                                    \
                                                 ,                                                          \
                                     # from y
                      (  arg_list_CopySource_From_and_To_xy [ 0 ] [ 1 ]  \
                                    +                                                                      \
                                     # to y
                         arg_list_CopySource_From_and_To_xy [ 1 ] [ 1 ]  \
                                ) / 2.0                                                                   \
                                     ]
        from_x = arg_list_CopySource_From_and_To_xy [ 0 ] [ 0 ]  \
                             - list_center_xy_of_copying_area [ 0 ]
        to_x =   arg_list_CopySource_From_and_To_xy [ 1 ] [ 0 ]  \
                             - list_center_xy_of_copying_area [ 0 ]
        from_y = arg_list_CopySource_From_and_To_xy [ 0 ] [ 1 ]  \
                             - list_center_xy_of_copying_area [ 1 ]
        to_y = arg_list_CopySource_From_and_To_xy [ 1 ] [ 1 ]  \
                             - list_center_xy_of_copying_area [ 1 ]
       #-------------------------------------------------
        list_rotation_cos_and_sin = [ 0.0 , 0.0 ]
        if ( arg_do_rotation == "Y" ) :
            radian_rotation = arg_rotation_degree_of_inserting_on_InsertedSide_Source  \
                                         * ( math.pi / 180.0 )
            list_rotation_cos_and_sin [ 0 ]  = math.cos ( radian_rotation )
            list_rotation_cos_and_sin [ 1 ]  = math.sin ( radian_rotation )
       #---------------------------------------------------
        self.iv_width_of_ImageData_InsertedSide_Generated =   \
               self.iv_list_ImageDataTwoDimensionHandling [ 3 ]  \
                         .get_width_of_ImageData ( )
        self.iv_height_of_ImageData_InsertedSide_Generated =   \
               self.iv_list_ImageDataTwoDimensionHandling [ 3 ]  \
                         .get_height_of_ImageData ( )
       #-------------------------------------------------
        x = from_x
        while ( x <=  to_x  ) :

            # print ( "==================================" )
            # print ( " Class = "  + CopyAndInsertImageDataV2.CV_CLASS_NAME
            #               + " , methode = " + methode_name )
            # print ( "x = " , x )
            # print ( "==================================" )

            y = from_y
            while ( y <=  to_y  ) :

                self.process_for_one_location_x_y ( \
                       arg_use_or_not_PatternImageData

                     ,  x
                     ,  y

                     ,  list_color_of_pixel_directed_x_and_y_on_PatternImageData

                     ,  arg_list_color_copying

                     ,  list_center_xy_of_copying_area
                     ,  arg_scale_rate_CopySource_to_InsertedSide
                     ,  arg_color_rate_CopySource_to_InsertedSide
                     ,  arg_list_Center_xy_of_inserting_on_InsertedSide_Source

                     ,  arg_do_rotation
                     ,  list_rotation_cos_and_sin
                                                        )
            #-----------------------------
                y += 1
       #-----------------------------
            x += 1
    #-------------------------------------

        print ( "==================================" )
        print ( "Exit from Class = "  + CopyAndInsertImageDataV2.CV_CLASS_NAME
                          + " , methode = " + methode_name )
        print ( "==================================" )

#=================================
    def  process_for_one_location_x_y (   self  \
                      ,   arg_use_or_not_PatternImageData

                      ,  arg_x
                      ,  arg_y

                      ,  arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData

                      ,  arg_list_color_copying

                      ,  arg_list_center_xy_of_copying_area
                      ,  arg_scale_rate_CopySource_to_InsertedSide
                      ,  arg_color_rate_CopySource_to_InsertedSide
                      ,  arg_list_Center_xy_of_inserting_on_InsertedSide_Source

                      ,  arg_do_rotation
                      ,  list_rotation_cos_and_sin
                                       )  :

        methode_name = "process_for_one_location_x_y"

       # print ( "==================================" )
       # print ( "Class = "  + CopyAndInsertImageDataV2.CV_CLASS_NAME
       #                   + " , methode = " + methode_name )
       # print ( "arg_x = " , arg_x )
       # print ( "arg_y = " , arg_y )
       # print ( "==================================" )

        get_location_x = int ( arg_list_center_xy_of_copying_area [ 0 ] + arg_x )
        get_location_y = int ( arg_list_center_xy_of_copying_area [ 1 ] + arg_y )

        w_x = arg_x * arg_scale_rate_CopySource_to_InsertedSide
        w_y = arg_y * arg_scale_rate_CopySource_to_InsertedSide
                     #----------------------------
        if ( arg_do_rotation == "Y" ) :
            w_rotated_x =    \
                ( list_rotation_cos_and_sin [ 0 ] * w_x )  \
                 -                                         \
                 ( list_rotation_cos_and_sin [ 1 ] * w_y )
            w_rotated_y =    \
                ( list_rotation_cos_and_sin [ 1 ] * w_x )  \
                 +                                         \
                 ( list_rotation_cos_and_sin [ 0 ] * w_y )
               #---------------------
            w_x = w_rotated_x
            w_y = w_rotated_y
            #------------------------------------

        put_location_x = int ( arg_list_Center_xy_of_inserting_on_InsertedSide_Source [ 0 ]\
                                            + w_x )
        put_location_y = int ( arg_list_Center_xy_of_inserting_on_InsertedSide_Source [ 1 ] \
                                            + w_y )

        if (  (  put_location_x < 0 )                 \
            or                                                \
              (  put_location_x >=                  \
                    self.iv_width_of_ImageData_InsertedSide_Generated )    \
            or                                               \
               (  put_location_y < 0 )                 \
            or                                                \
               (  put_location_y >=        \
                       self.iv_height_of_ImageData_InsertedSide_Generated )     \
          ) :
                         # area over --> not draw, no error message
            return "N"

                 #--------------------------------------
        list_color_data_for_put = \
            self.decide_color_for_put (    \
                         arg_use_or_not_PatternImageData

                      ,  arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData

                      ,  arg_list_color_copying

                      ,  arg_color_rate_CopySource_to_InsertedSide

                      ,  get_location_x
                      ,  get_location_y

                      ,  put_location_x
                      ,  put_location_y
                                                    )

        if (  list_color_data_for_put [ 0 ] == "N" ) :
                   # on this location, not draw color exist
                   # so, this location must not be draw
            return "N"
      #------------------------------------
        self.iv_list_ImageDataTwoDimensionHandling [ 3 ]   \
               .put_data_of_one_pixel ( \
                            CopyAndInsertImageDataV2.CV_CLASS_NAME
                         ,  methode_name
                              # in the commonly used mathematical XY cordinates
                         , put_location_x
                         , put_location_y

                         , list_color_data_for_put [ 1 ]   # arg_color_data_Blue
                         , list_color_data_for_put [ 2 ]   #arg_color_data_Green
                         , list_color_data_for_put [ 3 ]   #arg_color_data_Red
                                                    )
        return "Y"

    #------------------------------------------------------------
    def  decide_color_for_put (   self \
                      ,   arg_use_or_not_PatternImageData

                       ,  arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData

                      ,  arg_list_color_copying

                      ,  arg_color_rate_CopySource_to_InsertedSide

                      ,  arg_get_location_x
                      ,  arg_get_location_y

                      ,  arg_put_location_x
                      ,  arg_put_location_y
                                         ) :

        methode_name = "decide_color_for_put"

       #print ( "==================================" )
       # print ( "Enter into , Class = "  + CopyAndInsertImageDataV2.CV_CLASS_NAME
       #                   + " , methode = " + methode_name )
       #print ( "==================================" )

        list_return = [ "Y" , 0 , 0 , 0 ]

        color_data_CopySource = \
               self.iv_list_ImageDataTwoDimensionHandling [ 0 ]    \
                    .get_data_of_one_pixel ( \
                             CopyAndInsertImageDataV2.CV_CLASS_NAME
                          ,  methode_name
                              # in the commonly used mathematical XY cordinates
                         ,  arg_get_location_x
                         ,  arg_get_location_y
                                                         )
        list_return [ 1 ] = color_data_CopySource [ 0 ]
        list_return [ 2 ] = color_data_CopySource [ 1 ]
        list_return [ 3 ] = color_data_CopySource [ 2 ]
       #-----------------------------------
        if (     \
                          # Blue
                                                                # from
              ( color_data_CopySource [ 0 ] < arg_list_color_copying [ 0 ] [ 0 ] )  \
              or \
                                                                # to
              ( color_data_CopySource [ 0 ] > arg_list_color_copying [ 1 ] [ 0 ] )  \
              or \
                          # Green
                                                                # from
              ( color_data_CopySource [ 1 ] < arg_list_color_copying [ 0 ] [ 1 ] )  \
              or \
                                                                # to
              ( color_data_CopySource [ 1 ] > arg_list_color_copying [ 1 ] [ 1 ] )  \
              or \
                           # Red
                                                                # from
              ( color_data_CopySource [ 2 ] < arg_list_color_copying [ 0 ] [ 2 ] )  \
              or \
                                                                # to
              ( color_data_CopySource [ 2 ] > arg_list_color_copying [ 1 ] [ 2 ] )  \
           )   :
                     # this location has color , that indicate, must not be copied
            list_return [ 0 ] = "N"

            return  list_return
        #----------------------------------------------
        if (  arg_use_or_not_PatternImageData == "Y" ) :
                             #use PatternImageData
            color_data_PatternImageData = \
                  self.iv_list_ImageDataTwoDimensionHandling [ 1 ]    \
                      .get_data_of_one_pixel ( \
                               CopyAndInsertImageDataV2.CV_CLASS_NAME
                           ,  methode_name
                                # in the commonly used mathematical XY cordinates
                           ,  arg_get_location_x
                           ,  arg_get_location_y
                                                         )

           # print ( "==================================" )
           # print ( "Class = "  + CopyAndInsertImageDataV2.CV_CLASS_NAME
           #                   + " , methode = " + methode_name )
           # print ( "arg_get_location_x = " \
           #               ,  arg_get_location_x )
           # print ( "arg_get_location_y = " \
           #               ,  arg_get_location_y )
           # print ( "color_data_PatternImageData = " \
           #               ,  color_data_PatternImageData )
           # print ( "arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData = " \
           #               ,  arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData )
           # print ( "==================================" )

                          #----------------------------
            if (  ( color_data_PatternImageData  [ 0 ] !=                                                          \
                        arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData [ 0 ] )  \
                  or                                                                                                                  \
                  ( color_data_PatternImageData  [ 1 ] !=                                                          \
                        arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData [ 1 ] )  \
                  or                                                                                                                  \
                  ( color_data_PatternImageData  [ 2 ] !=                                                          \
                           arg_list_color_of_pixel_directed_x_and_y_on_PatternImageData [ 2 ] )   \
              ) :
                           #color on ( x , y ) , not equal,
                           #     color_of_pixel_directed_x_and_y_on_PatternImageData
                           #   , so , this pixel must not be copied
                list_return [ 0 ] = "N"
                return  list_return
          #----------------------------------------------------
        color_data_InsertedSideSource = \
               self.iv_list_ImageDataTwoDimensionHandling [ 2 ]   \
                    .get_data_of_one_pixel ( \

                          CopyAndInsertImageDataV2.CV_CLASS_NAME
                       ,  methode_name
                              # in the commonly used mathematical XY cordinates
                       ,  arg_put_location_x
                       ,  arg_put_location_y
                               )
          #----------------------------------------------------
        for i in range ( 0 , 3 ) :
            w_color_CopySource = \
                        color_data_CopySource [ i ] \
                           * arg_color_rate_CopySource_to_InsertedSide
            w_color_InsertedSideSource =  \
                        color_data_InsertedSideSource [ i ] \
                           * (  1.0 - arg_color_rate_CopySource_to_InsertedSide )
            w_color_mixed = int ( w_color_CopySource +  w_color_InsertedSideSource )

            index_for_return = i + 1
            list_return [ index_for_return ] = w_color_mixed
            if (  w_color_mixed < 0 ) :
               list_return [ index_for_return ] = 0
            if (  w_color_mixed >  255 ) :
               list_return [ index_for_return ] = 255

     #----------------------------------------
        return  list_return

#-------------------------------------------------------------

----------

----------
5  [ TestCopyAndInsertImageDataV2 ]

ファイル名 [ TestCopyAndInsertImageDataV2.py ]

下記ソースリスト中の、
Test 1 の部分が動くことにより、
 2 で述べた、 [Fig 4]の画像 が、作成された。
Test 2 の部分が動くことにより、
 2 で述べた、 [Fig 5]の画像 が、作成された。
Test 3 の部分が動くことにより、
 2 で述べた、 [Fig 6]の画像 が、作成された。

----------

----------


import  CopyAndInsertImageDataV2

#=====================================
# Test
#=====================================

module_name = "___"
function_name = "Test"

#***************************************
abs_path_of_CopySource_ImageData      \
        = "E:ForPython/ForTest/Test_12/ImageData_1.png"
abs_path_of_CopySource_Pattern_ImageData      \
        = "E:ForPython/ForTest/Test_12/ImageData_1_Pattern.png"
abs_path_of_InsertedSide_Source_ImageData    \
        = "E:ForPython/ForTest/Test_12/ImageData_2.png"

list_CopySource_From_and_To_xy = [ [ 0 , 0 ] , [ 499 , 499 ] ]

list_color_copying = [ [ 0 , 0 , 0 ] , [ 253 , 253 , 253 ] ]

list_Center_xy_of_inserting_on_InsertedSide_Source = [ 350 , 250 ]

#*******************************************
ins_CopyAndInsertImageDataV2 = \
            CopyAndInsertImageDataV2        \
                   .CopyAndInsertImageDataV2 ( )
        #---------------------------                   
ins_CopyAndInsertImageDataV2            \
               .construct_ImageData ( 0  )
ins_CopyAndInsertImageDataV2            \
               .load_ImageData (  0 ,  abs_path_of_CopySource_ImageData )
        #---------------------------
ins_CopyAndInsertImageDataV2            \
               .construct_ImageData ( 1  )
ins_CopyAndInsertImageDataV2            \
               .load_ImageData (  1 ,  abs_path_of_CopySource_Pattern_ImageData )
        #---------------------------
ins_CopyAndInsertImageDataV2            \
               .construct_ImageData ( 2  )
ins_CopyAndInsertImageDataV2            \
               .load_ImageData (  2 ,  abs_path_of_InsertedSide_Source_ImageData )
        #---------------------------
ins_CopyAndInsertImageDataV2            \
               .construct_ImageData ( 3  )

               #===== Test 1 ==============================
ins_CopyAndInsertImageDataV2            \
               .load_ImageData (  3 ,  \
                       #************************************
                       abs_path_of_InsertedSide_Source_ImageData
                       #************************************
                                          )
                                          
use_or_not_PatternImageData = "N"   # not use PatternImageData
abs_path_of_CopySource_PatternImageData = " "
list_directed_x_and_y_on_PatternImageData = [ 0 , 0 ]
       #-----------
scale_rate_CopySource_to_InsertedSide = 0.6
color_rate_CopySource_to_InsertedSide = 0.8
do_rotation = "Y"
rotation_degree_of_inserting_on_InsertedSide_Source = 45
       #-----------
ins_CopyAndInsertImageDataV2   \
    .copy_and_insert_ImageData (
                            use_or_not_PatternImageData
                        ,   list_directed_x_and_y_on_PatternImageData
                         ,  list_color_copying
                         ,  list_CopySource_From_and_To_xy
                         ,  scale_rate_CopySource_to_InsertedSide
                         ,  color_rate_CopySource_to_InsertedSide
                         ,  list_Center_xy_of_inserting_on_InsertedSide_Source
                         ,  do_rotation
                         ,  rotation_degree_of_inserting_on_InsertedSide_Source
                                               )
abs_path_of_InsertedSide_Generated_ImageData    \
        = "E:ForPython/ForTest/Test_12/ImageData_Output_1.png"
ins_CopyAndInsertImageDataV2   \
    .write_InsertedSide_Generated_ImageData (   \
                    abs_path_of_InsertedSide_Generated_ImageData
                                                                      )

        #===== Test 2 ==============================
ins_CopyAndInsertImageDataV2            \
               .load_ImageData (  3 ,  \
                       #************************************
                       abs_path_of_InsertedSide_Source_ImageData
                       #************************************
                                          )

use_or_not_PatternImageData = "Y"   # use PatternImageData
list_directed_x_and_y_on_PatternImageData [ 0 ] = 180
list_directed_x_and_y_on_PatternImageData [ 1 ] = 60

       #-----------
scale_rate_CopySource_to_InsertedSide = 0.95
color_rate_CopySource_to_InsertedSide = 0.8
do_rotation = "N"
rotation_degree_of_inserting_on_InsertedSide_Source = 0
       #-----------
ins_CopyAndInsertImageDataV2   \
    .copy_and_insert_ImageData (   \
                            use_or_not_PatternImageData
                        ,   list_directed_x_and_y_on_PatternImageData
                         ,  list_color_copying
                         ,  list_CopySource_From_and_To_xy
                         ,  scale_rate_CopySource_to_InsertedSide
                         ,  color_rate_CopySource_to_InsertedSide
                         ,  list_Center_xy_of_inserting_on_InsertedSide_Source
                         ,  do_rotation
                         ,  rotation_degree_of_inserting_on_InsertedSide_Source
                                           )

abs_path_of_InsertedSide_Generated_ImageData    \
        = "E:ForPython/ForTest/Test_12/ImageData_Output_2.png"
ins_CopyAndInsertImageDataV2   \
    .write_InsertedSide_Generated_ImageData (   \
                        abs_path_of_InsertedSide_Generated_ImageData
                                                                      )

            #===== Test 3 ==============================
ins_CopyAndInsertImageDataV2            \
               .load_ImageData (  3 ,  \
                       #************************************
                       abs_path_of_InsertedSide_Source_ImageData
                       #************************************
                                          )

use_or_not_PatternImageData = "Y"   # use PatternImageData
list_directed_x_and_y_on_PatternImageData [ 0 ] = 90
list_directed_x_and_y_on_PatternImageData [ 1 ] = 250
       #-----------
scale_rate_CopySource_to_InsertedSide = 0.95
color_rate_CopySource_to_InsertedSide = 0.8
do_rotation = "N"
rotation_degree_of_inserting_on_InsertedSide_Source = 0
       #-----------
ins_CopyAndInsertImageDataV2   \
    .copy_and_insert_ImageData (
                            use_or_not_PatternImageData
                        ,   list_directed_x_and_y_on_PatternImageData
                         ,  list_color_copying
                         ,  list_CopySource_From_and_To_xy
                         ,  scale_rate_CopySource_to_InsertedSide
                         ,  color_rate_CopySource_to_InsertedSide
                         ,  list_Center_xy_of_inserting_on_InsertedSide_Source
                         ,  do_rotation
                         ,  rotation_degree_of_inserting_on_InsertedSide_Source
                                           )

abs_path_of_InsertedSide_Generated_ImageData    \
        = "E:ForPython/ForTest/Test_12/ImageData_Output_3.png"
ins_CopyAndInsertImageDataV2   \
    .write_InsertedSide_Generated_ImageData (   \
                        abs_path_of_InsertedSide_Generated_ImageData
                                                                      )

#-------------------------------------------------------------

----------

----------

Python(パイソン) プログラム作ってみた インデックス へ

この記事が気に入ったらサポートをしてみませんか?