¿Cómo hacer transparente el fondo de las imágenes hechas por JSL usando Python?No lo logré así.
¡Gracias!
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);

Automatización y scriptingVentanasPregunta: ¿Cómo hacer transparente el fondo de las imágenes creadas con JSL usando Python?Python Enviar(img);
equivocado.
Tenga en cuenta que las imágenes no deben guardarse durante el procesamiento.
¡Gracias!
Re: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando Python?El problema clave es convertir los datos de la imagen JMP en un formato compatible con Python. Con el código anterior, obtendrá una imagen RGBA en Python con la que podrá trabajar.
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
]\");
Aquí es donde entran en juego las limitaciones de la IA. Para hacerlo eficientemente, es necesario comprender las capacidades que ofrece JSL y cómo transferir esos datos a Python de forma que puedan ser utilizados por las API de Python. El índice de scripts de JMP es tu aliado; lo uso como referencia.
Re: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando Python?Parece que Python es más conveniente para procesar y guardar imágenes.
¡Gracias expertos!

Re: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando Python?Parece que Python es más conveniente para procesar y guardar imágenes.Quiero hacer un cuadro así.
Es una lástima que JSL no tenga la función de hacer directamente transparente el fondo gráfico.

Re: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando Python?Ver índice de scripts: Imagen
img << Transparencia( 0. ); // establece el nivel de transparencia de toda la imagen 0..1 0 => transparente, 1 => opaco
Si desea que solo el fondo sea transparente, << get pixels( "rgba" ) luego edite las matrices para encontrar los píxeles blancos y configure su transparencia a 0, luego use << set pixels( "rgba", { r, g, b, a} ) para establecer las actualizaciones nuevamente en la imagen.
Pregunta: ¿Cómo hacer transparente el fondo de las imágenes creadas con JSL usando Python?JMP 18 Python Send() no gestiona una imagen JMP. Los tipos de tabla de datos tenían prioridad en la versión 18. JMP 19 ofrece compatibilidad mínima con imágenes, lo que permite insertarlas en la tabla de datos desde Python. Actualmente, no existen accesores a los datos de imagen subyacentes desde Python en JMP 19 EA.
Re: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando Python?¡Gracias expertos!
Intenté escribir así y también le pregunté a la IA, pero aún así fallé.
Sabía antes que esto podría hacer que la imagen sea más clara, pero no es transparente.
Craige presentó específicamente una sugerencia para lograr transparencia de fondo (en JMP 17, pero JMP18 no mejoró).
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: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando 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/mp/627070#M82571
Re: ¿Cómo hacer transparente el fondo de las imágenes hechas con JSL usando Python?