<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to make the background of images made by JSL transparent using python? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871081#M103472</link>
    <description>&lt;P&gt;&lt;SPAN&gt;See scripting index: Image&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;img &amp;lt;&amp;lt; Transparency( 0. ); &amp;nbsp; &amp;nbsp; &amp;nbsp;// sets entire image's transparency level 0..1 &amp;nbsp; 0 =&amp;gt; transparent, 1 =&amp;gt; opaque&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want just the background transparent, &amp;lt;&amp;lt; get pixels( "rgba" ) then edit the arrays to find the white pixels and setting their transparency to 0, then use &amp;lt;&amp;lt; set pixels( "rgba", { r, g, b, a} ) set the updates back to the image.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Apr 2025 12:44:52 GMT</pubDate>
    <dc:creator>Paul_Nelson</dc:creator>
    <dc:date>2025-04-30T12:44:52Z</dc:date>
    <item>
      <title>How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/870707#M103429</link>
      <description>&lt;P&gt;I didn't succeed like this.&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/Big Class.jmp");

p1 = dt &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; Get Picture;


img_binary = img &amp;lt;&amp;lt; 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] &amp;gt;= 240) &amp;amp; (data[:, :, 1] &amp;gt;= 240) &amp;amp; (data[:, :, 2] &amp;gt;= 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);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-04-29_13-43-39.png" style="width: 705px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75290iE3E8E21B0782CC3F/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-04-29_13-43-39.png" alt="2025-04-29_13-43-39.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 05:46:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/870707#M103429</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-29T05:46:07Z</dc:date>
    </item>
    <item>
      <title>回复： How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/870717#M103430</link>
      <description>&lt;P&gt;Python Send(img);&lt;BR /&gt;wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that the pictures should not be saved during the processing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 08:59:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/870717#M103430</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-29T08:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/870978#M103459</link>
      <description>&lt;P&gt;The key issue you are having is getting the JMP image data into a format you can work with in Python. &amp;nbsp;Taking your above code, This will give you an RGBA image in Python that you can then work with,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

p1 = dt &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; Get Picture;

m = img &amp;lt;&amp;lt; 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

]\");&lt;/PRE&gt;
&lt;P&gt;This is where limitations of AI come in, to do this efficiently you need to understand what capabilities that JSL provides and how to get that data across to Python in a manner that can be consumed buy the Python APIs. &amp;nbsp;The JMP scripting index is your friend, I use it as a go to reference.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 18:23:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/870978#M103459</guid>
      <dc:creator>Paul_Nelson</dc:creator>
      <dc:date>2025-04-29T18:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871029#M103466</link>
      <description>&lt;P&gt;&lt;SPAN&gt;It seems that python is more convenient for processing and saving images.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Experts!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-04-30_10-27-27.png" style="width: 866px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75334iF3F528CC8F9C3DEB/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-04-30_10-27-27.png" alt="2025-04-30_10-27-27.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 02:29:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871029#M103466</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-30T02:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871031#M103467</link>
      <description>&lt;P class="_tgt transPara grammarSection"&gt;&lt;SPAN class="transSent" data-group="0-0"&gt;It seems that python is more convenient for processing and saving images.&lt;/SPAN&gt;&lt;SPAN class="transSent" data-group="0-1"&gt;I want to make such a picture.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="_tgt transPara grammarSection"&gt;&lt;SPAN class="transSent" data-group="1-0"&gt;It's a pity that JSL doesn't have the function of directly making the graphic background transparent.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="_tgt transPara grammarSection"&gt;&lt;SPAN class="transSent" data-group="1-0"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-04-29_08-32-52.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75335i77E3C708112B3C9E/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-04-29_08-32-52.png" alt="2025-04-29_08-32-52.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 02:32:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871031#M103467</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-30T02:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871081#M103472</link>
      <description>&lt;P&gt;&lt;SPAN&gt;See scripting index: Image&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;img &amp;lt;&amp;lt; Transparency( 0. ); &amp;nbsp; &amp;nbsp; &amp;nbsp;// sets entire image's transparency level 0..1 &amp;nbsp; 0 =&amp;gt; transparent, 1 =&amp;gt; opaque&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want just the background transparent, &amp;lt;&amp;lt; get pixels( "rgba" ) then edit the arrays to find the white pixels and setting their transparency to 0, then use &amp;lt;&amp;lt; set pixels( "rgba", { r, g, b, a} ) set the updates back to the image.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 12:44:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871081#M103472</guid>
      <dc:creator>Paul_Nelson</dc:creator>
      <dc:date>2025-04-30T12:44:52Z</dc:date>
    </item>
    <item>
      <title>回复： How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871082#M103473</link>
      <description>&lt;P&gt;JMP 18 Python Send() does not know how to handle a JMP Image. Data table types had priority in 18. &amp;nbsp;JMP 19 has minimal support for Image so that Images can be placed into the data table from Python. &amp;nbsp;At present there are no accessors to the underlying image data from Python in JMP 19 EA.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 12:54:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871082#M103473</guid>
      <dc:creator>Paul_Nelson</dc:creator>
      <dc:date>2025-04-30T12:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871107#M103474</link>
      <description>&lt;P&gt;Thanks Experts!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="_tgt transPara grammarSection"&gt;&lt;SPAN class="transSent" data-group="0-0"&gt;I tried to write like this and also asked the AI, but still failed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="_tgt transPara grammarSection"&gt;&lt;SPAN class="transSent highlight" data-group="1-0"&gt;I knew before that this could make the picture lighter, but it's not transparent.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="_tgt transPara grammarSection"&gt;&lt;SPAN class="transSent" data-group="2-0"&gt;Craige specifically put forward a suggestion for achieving background transparency (in JMP 17, but JMP18 did not improve).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="_tgt transPara grammarSection"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/Big Class.jmp");
p1 = dt &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; Get Picture;
m = img &amp;lt;&amp;lt; Get Pixels("rgba");
size_info = img &amp;lt;&amp;lt; Get Size;
img_width = If(N Items(size_info) &amp;gt;= 1, size_info[1], 0);
img_height = If(N Items(size_info) &amp;gt;= 2, size_info[2], 0);
n = m;
white_pixels = Loc(m[0, 0, 1] == 255 &amp;amp; m[0, 0, 2] == 255 &amp;amp; m[0, 0, 3] == 255);
for(k = 1, k &amp;lt;= N Rows(white_pixels), k++,
	i = white_pixels[k, 1];
	j = white_pixels[k, 2];
	n[i, j, 4] = 0
);
img &amp;lt;&amp;lt; Set Pixels("rgba", n);
win2 = NewWindow("Transformed - White Transparent", img);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Apr 2025 14:09:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871107#M103474</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-30T14:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871108#M103475</link>
      <description>&lt;P&gt;&lt;A href="https://community.jmp.com/t5/JMP-Wish-List/Transparent-background-color-for-graphs/idi-p/627431" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/JMP-Wish-List/Transparent-background-color-for-graphs/idi-p/627431&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/How-to-use-JSL-graph-background-for-transparent-graphics/m-p/627070#M82571" target="_blank"&gt;https://community.jmp.com/t5/Discussions/How-to-use-JSL-graph-background-for-transparent-graphics/m-p/627070#M82571&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 14:15:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871108#M103475</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-30T14:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the background of images made by JSL transparent using python?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871112#M103476</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-04-18_18-22-01.png" style="width: 491px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75350i20E24AC362F03C23/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-04-18_18-22-01.png" alt="2025-04-18_18-22-01.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 14:17:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-the-background-of-images-made-by-JSL-transparent/m-p/871112#M103476</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-04-30T14:17:35Z</dc:date>
    </item>
  </channel>
</rss>

