

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>numpy &#8211; Max的程式語言筆記</title>
	<atom:link href="https://stackoverflow.max-everyday.com/tag/numpy/feed/" rel="self" type="application/rss+xml" />
	<link>https://stackoverflow.max-everyday.com</link>
	<description>我要當一個豬頭，快樂過每一天</description>
	<lastBuildDate>Fri, 02 Jul 2021 18:07:11 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/max-stackoverflow-256.png</url>
	<title>numpy &#8211; Max的程式語言筆記</title>
	<link>https://stackoverflow.max-everyday.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>numpy 的陣列內容比對</title>
		<link>https://stackoverflow.max-everyday.com/2021/07/numpy-array-boolean-compare/</link>
					<comments>https://stackoverflow.max-everyday.com/2021/07/numpy-array-boolean-compare/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Fri, 02 Jul 2021 18:07:10 +0000</pubDate>
				<category><![CDATA[Python筆記]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://stackoverflow.max-everyday.com/?p=3830</guid>

					<description><![CDATA[最近看到別人分享的一個副程式，因為想要修改，可是...]]></description>
										<content:encoded><![CDATA[
<p>最近看到別人分享的一個副程式，因為想要修改，可是「完全」無法理解，為什麼可以這樣去使用，原來是變成了自定義的物件，所以可以取出特定項目進行一一的比對。</p>



<p>先來看看原本的程式碼：</p>



<pre class="wp-block-preformatted">import numpy as np

def changeColor(im, from_rgb_value, to_rgb_value):
    data = np.array(im)
    red, green, blue = data[:,:,0], data[:,:,1], data[:,:,2]
    r1, g1, b1 = from_rgb_value
    mask = (red == r1) &amp; (green == g1) &amp; (blue == b1)</pre>



<p>看到這裡，沒想到 red == r1 的比對是 array 裡的項目一一比對，而不是2個boolean object 內容的比對。而比對的結果居然還可以放回去 mask array 裡，這個真的很神奇。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2021/07/numpy-array-boolean-compare/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PIL 的 getpixel 似乎略慢</title>
		<link>https://stackoverflow.max-everyday.com/2020/10/pil-getpixel-numpy/</link>
					<comments>https://stackoverflow.max-everyday.com/2020/10/pil-getpixel-numpy/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Tue, 20 Oct 2020 17:30:53 +0000</pubDate>
				<category><![CDATA[Python筆記]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[PIL]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=3566</guid>

					<description><![CDATA[由於想針對影像做處理，使用 loop 去拿ima...]]></description>
										<content:encoded><![CDATA[
<p>由於想針對影像做處理，使用 loop 去拿image 裡的pixel 使用 image.getpixel 似乎太沒有效率，於是使用 numpy.asarray() 把 PIL image object 轉成 array. </p>



<p>使用的範例圖片 width: 921, height 1001, 服用下面的 code 後：</p>



<pre class="wp-block-preformatted">import PIL
import numpy
from PIL import Image
im = Image.open('U_51234.bmp')
data = numpy.asarray(im)
print("shape:", data.shape)
print("100,150:",data[100,150])
print("100,150:",data[100][150])</pre>



<p>取得 shape: (1001, 921)</p>



<p>所以是先 h 再 w, 如果要直接 access array 需要先放 y axis ，再使用 x axis, 與原先的 getpixel(x,y) 順序會相反。</p>



<hr class="wp-block-separator"/>



<p>Convert between PIL image and NumPy ndarray</p>



<pre class="wp-block-code"><code>image = Image.open(“max-demo.jpg”)   # image is a PIL image 
array = numpy.array(image)          # array is a numpy array 
image2 = Image.fromarray(array)   # image2 is a PIL image
</code></pre>



<p>Convert between PIL image and PyOpenCV matrix</p>



<pre class="wp-block-code"><code>image = Image.open(“max-demo.jpg”)                  # image is a PIL image
mat = pyopencv.Mat.from_pil_image(image)  # mat is a PyOpenCV matrix 
image2 = mat.to_pil_image()                        # image2 is a PIL image
</code></pre>



<p>Convert between OpenCV image and NumPy ndarray</p>



<pre class="wp-block-code"><code>cimg = cv.LoadImage("max-demo.jpg", cv.CV_LOAD_IMAGE_COLOR)   # cimg is a OpenCV image 
pimg = Image.fromstring("RGB", cv.GetSize(cimg), cimg.tostring())  # pimg is a PIL image 
array = numpy.array(pimg)     # array is a numpy array 
pimg2 = cv.fromarray(array)    # pimg2 is a OpenCV image</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2020/10/pil-getpixel-numpy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
