如何使用python讓JSL製作的圖像背景透明?我這樣子沒能成功。
謝謝!
dt = Open("$SAMPLE_DATA/Big Class.jmp");
p1 = dt << Graph Builder(
Show Control Panel(0),
Variables(X(:height), Y(:weight), Overlay(:sex)),
Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2)))
);
img = p1 << Get Picture;
img_binary = img << Get Blob("PNG");
base64_img = Blob To Base64(img_binary);
Python Send("base64_img", base64_img);
Python Submit("
import base64
from PIL import Image
import numpy as np
import io
def remove_white_background(img_data_bytes):
img = Image.open(io.BytesIO(img_data_bytes))
if img.mode != 'RGBA':
img = img.convert('RGBA')
data = np.array(img)
white_pixels = (data[:, :, 0] >= 240) & (data[:, :, 1] >= 240) & (data[:, :, 2] >= 240)
data[white_pixels, 3] = 0
new_img = Image.fromarray(data)
output = io.BytesIO()
new_img.save(output, format='PNG')
return output.getvalue()
img_data_bytes = base64.b64decode(base64_img)
transparent_img_binary = remove_white_background(img_data_bytes)
");
transparent_img_binary = Python Get("transparent_img_binary");
transparent_img = New Image(transparent_img_binary);

自動化和腳本視窗回覆:如何使用python使JSL製作的圖像背景透明?Python 發送(圖片);
錯誤的。
注意,處理過程中不要儲存圖片。
謝謝!
回覆:如何使用 python 使 JSL 製作的圖像背景透明?您遇到的關鍵問題是將 JMP 映像資料轉換為可以在 Python 中使用的格式。按照上面的程式碼,這將為你提供一個 Python 格式的 RGBA 映像,你可以用它來處理,
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
p1 = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);
img = p1 << Get Picture;
m = img << Get Pixels( "rgba" ); // See scripting index for docs on get pixel
python send(m); // Sends list of vectors { [r],[g],[b],[a] }
python submit("\[
from PIL import Image
import numpy as np
print(m.__class__)
# JMP image values are 0..1 so covert and make numpy array
rgb_uint8 = (np.dstack((m[0],m[1],m[2],m[3])) * 255.999) .astype(np.uint8)
pyimg = Image.fromarray(rgb_uint8,"RGBA"). #you now have a PIL.Image in Python.
pyimg.save(jmp.HOME+'pyimg.png'). # here I saved just to prove image made it through
]\");
這就是 AI 的限制所在,為了有效地做到這一點,您需要了解 JSL 提供的功能以及如何以可透過 Python API 使用的方式將資料傳輸到 Python。 JMP 腳本索引是你的朋友,我使用它作為參考。
回覆:如何使用 python 使 JSL 製作的圖像背景透明?看來python對於影像的處理與保存還是比較方便的。
謝謝專家!

回覆:如何使用 python 使 JSL 製作的圖像背景透明?看來python對於影像的處理與保存還是比較方便的。我想製作這樣一幅畫。
可惜的是JSL沒有直接讓圖形背景透明化的功能。

回覆:如何使用 python 使 JSL 製作的圖像背景透明?請參閱腳本索引:圖像
img << 透明度( 0. ) ; // 設定整個影像的透明度等級 0..1 0 => 透明,1 => 不透明
如果您只希望背景透明,<<取得像素(“rgba”)然後編輯陣列以查找白色像素並將其透明度設為0,然後使用<<設定像素(“rgba”,{r,g,b,a})將更新設定回影像。
回覆:如何使用python使JSL製作的圖像背景透明?JMP 18 Python Send() 不知道如何處理 JMP 影像。資料表類型在 18 中具有優先權。 JMP 19 對映像的支援最少,因此可以將映像從 Python 放入資料表中。目前,JMP 19 EA 中沒有來自 Python 的底層影像資料存取器。
回覆:如何使用 python 使 JSL 製作的圖像背景透明?謝謝專家!
我嘗試這樣寫,也問過AI,但還是失敗了。
我之前知道這可以使圖片變亮,但它不透明。
Craige特別提出了實現背景透明度的建議(在JMP 17中,但JMP18沒有改進)。
dt = Open("$SAMPLE_DATA/Big Class.jmp");
p1 = dt << Graph Builder(
Show Control Panel(0), Show Legend(0), Show Title(0), Show Footer(0), Show X Axis(0), Show Y Axis(0), Show X Axis Title(0), Show Y Axis Title(0),
Variables(X(:height), Y(:weight), Overlay(:sex)),
Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2)))
);
img = p1 << Get Picture;
m = img << Get Pixels("rgba");
size_info = img << Get Size;
img_width = If(N Items(size_info) >= 1, size_info[1], 0);
img_height = If(N Items(size_info) >= 2, size_info[2], 0);
n = m;
white_pixels = Loc(m[0, 0, 1] == 255 & m[0, 0, 2] == 255 & m[0, 0, 3] == 255);
for(k = 1, k <= N Rows(white_pixels), k++,
i = white_pixels[k, 1];
j = white_pixels[k, 2];
n[i, j, 4] = 0
);
img << Set Pixels("rgba", n);
win2 = NewWindow("Transformed - White Transparent", img);回覆:如何使用 python 使 JSL 製作的圖像背景透明?https://community.jmp.com/t5/JMP-Wish-List/Transparent-background-color-for-graphs/idi-p/627431
https://community.jmp.com/t5/Discussions/How-to-use-JSL-graph-background-for-transparent-graphics/mp/627070#M82571
回覆:如何使用 python 使 JSL 製作的圖像背景透明?