はじめに
オープンソース コンピューター ビジョン ライブラリ (OpenCV) は、画像やビデオ ファイルなどの視覚入力を処理するための、無料で利用できるプログラミング ツールを提供します。これには、さまざまなプログラミング言語を介してアクセスできる、すぐに使用できる関数が多数含まれています。ここに投稿した例では Python を使用しています。したがって、コードを理解したい場合は、少なくとも Python と NumPy の基本的な知識が必要です。 OpenCV の入門を探している場合は、このリンクが非常に役立つ可能性があります: [https://dev.to/arpitmandliya/opencv-python-tutorial-3dac]。
ピクセルが画像を作る仕組み
ほとんどの場合、コンピューター画像は RGB (OpenCV では BGR) モデルに基づいています。これは、ピクセルの色が Red、Green、および Blue のコンポーネントの混合であることを意味します。他のモデル (例: Hue、Saturation、Value) やベクター グラフィックス (SVG または PDF) もありますが、説明は省略します。ここにあります。
コンピューター上の画像は、色情報を含むピクセルの集合として表現できます。より専門的な用語で言えば、画像は 3 次元配列 (または 3 つのカラー チャネルを持つピクセルのマトリックス) であり、最初の 2 次元が画像のサイズ (高さと幅) を決定し、3 番目の次元には赤、緑の値が含まれます。および青 (各色は 0 ~ 255 の値)。画像にカラー チャネルが 1 つだけある場合 (8 ビット画像)、それは 0 (黒) から 255 (白) の範囲のさまざまなグレー値を持つグレースケール画像になります。 図 1 はそれを示しています。
図 1: 画像は配列として表されます。右側はカラー イメージの例です。赤、緑、青の値の範囲は 0 ~ 255 (0、0、255 は青) です。左側は、さまざまなグレーの色合いを表す 1 つのチャネルを持つグレースケール イメージです。
色情報をさまざまなサイズのドットに変換する
上で説明した原則は、NumPy ライブラリと OpenCV ライブラリを使用して Python で画像編集を実行するために適用できます。この例では、ループを使用して、NumPy 配列として表される画像を処理します。このループは画像内のすべてのピクセルを反復するのではなく、一定の間隔でピクセルをスキップします (たとえば、10 番目のピクセルごとに処理します)。処理された各ピクセルのグレースケール値は、ドットのサイズを決定するために使用されます (たとえば、グレースケール値 100 は特定のドット サイズに対応します)。これらのドットは、元の画像の色情報を使用して、元の画像の空のコピー上に描画されます。要約すると、元のピクセルの色情報に基づいてさまざまなサイズのドットが描画されるイメージ コピーを作成します (図 2 を参照)。
図 2: ドットを描画するには、元の画像のピクセルの色情報が使用されます。ドットのサイズを決定するには、元の画像のグレースケール バージョンが使用されます。
以下にコードがあり、考えられる結果を 図 3 に示します。
import numpy as np import cv2 # load an image; image has to be in working directory when giving no path information img = cv2.imread('FlowerPower.jpg',cv2.IMREAD_UNCHANGED) # show the dimensions of the image array print(img.shape) # choose a resizing factor for the whole image; to depict it on computer screen resizing = .2 #convert original image to greyscale image img_grey = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # make a copy of the orignal image img_output = img.copy() # make a white canvas by assigning the color white (255,255, 255) to each pixel # [:,:] covers all values of the first and second array dimension img_output[:,:] = [255,255,255] # or with black [0,0,0] or any other color # Settings for looping over the image step_width = 40 # steps of loop; here: every 30th pixel # - 1 fills circle that is drawn onto output image; positive value define # line thickness of circle thickness = -1 perc = .2 # size factor for drawing circles/dots onto output image # for loops running over the first two dimensions of the array (width and height) # step_width defines which pixels are included for i in range(2, img.shape[0] - step_width, step_width): for u in range(2, img.shape[1] - step_width, step_width): # radius (dot size) is based on the value of greyscale version of original image # at the current index; e.g., pixel at i = 10, u = 30 might have 123 # perc variable modifies dot size radius = int((255-img_grey[i,u])*perc) +1 if radius <p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173272628418625.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="Making a simple pointillism painting using OpenCv."><br> <em>図 3: 右側には元のイメージが表示され、左側にはここで示されているコードに基づく点線バージョンが表示されます。</em></p> <p>私が包括的な方法でコードを提示し、誰かがそれを役に立つと思ってくれれば幸いです。よかったら遊んでみてください。円を長方形に置き換え、異なるサイズの円を選択し、ループのステップ幅などの値を変更して、何が起こるかを確認してください。 </p>
以上がOpenCvを使用して簡単な点描絵画を作成します。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

forhandlinglaredataSetsinpython、usenumpyArrays forbetterperformance.1)numpyarraysarememory-effictientandfasterfornumericaloperations.2)nusinnnnedarytypeconversions.3)レバレッジベクトル化は、測定済みのマネージメーシェイメージーウェイズデイタイです

inpython、listsusedynamicmemoryallocation with allocation、whilenumpyArraysalocatefixedmemory.1)listsallocatemorememorythanneededededinitivative.2)numpyArrayasallocateexactmemoryforements、rededicablebutlessflexibilityを提供します。

inpython、youcanspecthedatatypeyfelemeremodelernspant.1)usenpynernrump.1)usenpynerp.dloatp.ploatm64、フォーマーpreciscontrolatatypes。

numpyisessentialfornumericalcomputinginpythonduetoitsspeed、memory efficiency、andcomprehensivematicalfunctions.1)それは、performsoperations.2)numpyArraysaremoremory-efficientthanpythonlists.3)Itofderangeofmathematicaloperty

contiguousMemoryAllocationisucial forArraysは、ForeffienceAndfastelementAccess.1)iteenablesConstantTimeAccess、O(1)、DuetodirectAddresscalculation.2)itemprovesefficiencyByAllowingMultiblementFechesperCacheLine.3)itimplifieMememm

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 中国語版
中国語版、とても使いやすい

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

WebStorm Mac版
便利なJavaScript開発ツール

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。
