如何使用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
]\");
这就是人工智能的局限性所在。为了高效地做到这一点,你需要了解 JSL 提供的功能,以及如何将这些数据以 Python API 可访问的方式传输到 Python。JMP 脚本索引是你的好帮手,我经常使用它作为参考。
回复:如何使用 python 使 JSL 制作的图像背景透明?看来python对于图像的处理和保存还是比较方便的。
谢谢专家!

回复:如何使用 python 使 JSL 制作的图像背景透明?看来python对于图像的处理和保存还是比较方便的。我想制作这样一幅画。
可惜的是JSL没有直接让图形背景透明的功能。

回复:如何使用 python 使 JSL 制作的图像背景透明?参见脚本索引:图像
img << Transparency( 0. ); // 设置整个图像的透明度级别 0..1 0 => 透明, 1 => 不透明
如果您只希望背景透明,<<获取像素(“rgba”)然后编辑数组以查找白色像素并将其透明度设置为0,然后使用<<设置像素(“rgba”,{r,g,b,a})将更新设置回图像。
回复:如何使用python使JSL制作的图像背景透明?JMP 18 Python Send() 无法处理 JMP Image。在 JMP 18 中,数据表类型具有优先权。JMP 19 对 Image 的支持有限,因此可以通过 Python 将 Image 放入数据表中。目前,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);Re: How to make the background of images made by JSL transparent using python?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/m-p/627070#M82571
Re: How to make the background of images made by JSL transparent using python?