Come rendere trasparente lo sfondo delle immagini realizzate con JSL utilizzando Python?In questo modo non ci sono riuscito.
Grazie!
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);

Automazione e scriptingFinestreDomanda: Come rendere trasparente lo sfondo delle immagini create tramite JSL usando Python?Python Invia(img);
sbagliato.
Si prega di notare che le immagini non devono essere salvate durante l'elaborazione.
Grazie!
R: Come rendere trasparente lo sfondo delle immagini create con JSL usando Python?Il problema principale che stai riscontrando è convertire i dati dell'immagine JMP in un formato che possa essere elaborato in Python. Prendendo il codice precedente, otterrai un'immagine RGBA in Python con cui potrai poi lavorare.
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
]\");
È qui che entrano in gioco i limiti dell'intelligenza artificiale: per farlo in modo efficiente è necessario comprendere le capacità offerte da JSL e come trasferire tali dati a Python in modo che possano essere utilizzati tramite le API Python. L'indice di scripting JMP è un valido aiuto, lo uso come riferimento.
R: Come rendere trasparente lo sfondo delle immagini create con JSL usando Python?Sembra che Python sia più comodo per elaborare e salvare le immagini.
Grazie Esperti!

R: Come rendere trasparente lo sfondo delle immagini create con JSL usando Python?Sembra che Python sia più comodo per elaborare e salvare le immagini.Voglio realizzare un'immagine del genere.
È un peccato che JSL non abbia la funzione di rendere trasparente direttamente lo sfondo grafico.

R: Come rendere trasparente lo sfondo delle immagini create con JSL usando Python?Vedi l'indice di scripting: Immagine
img << Transparency( 0. ); // imposta il livello di trasparenza dell'intera immagine 0..1 0 => trasparente, 1 => opaco
Se vuoi che sia trasparente solo lo sfondo, << get pixels( "rgba" ) quindi modifica gli array per trovare i pixel bianchi e imposta la loro trasparenza su 0, quindi usa << set pixels( "rgba", { r, g, b, a} ) per reimpostare gli aggiornamenti sull'immagine.
Domanda: Come rendere trasparente lo sfondo delle immagini create tramite JSL usando Python?JMP 18 Python Send() non sa come gestire un'immagine JMP. I tipi di tabella dati avevano la priorità nella versione 18. JMP 19 offre un supporto minimo per le immagini, in modo che le immagini possano essere inserite nella tabella dati da Python. Al momento, non sono presenti funzioni di accesso ai dati dell'immagine sottostante da Python in JMP 19 EA.
R: Come rendere trasparente lo sfondo delle immagini create con JSL usando Python?Grazie Esperti!
Ho provato a scrivere in questo modo e ho anche chiesto all'IA, ma non ci sono riuscito.
Sapevo già che questo avrebbe potuto rendere l'immagine più chiara, ma non è trasparente.
Craige ha specificamente avanzato un suggerimento per ottenere la trasparenza dello sfondo (in JMP 17, ma JMP 18 non ha apportato miglioramenti).
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);R: Come rendere trasparente lo sfondo delle immagini create 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
R: Come rendere trasparente lo sfondo delle immagini create con JSL usando Python?