MarijaM Posted October 17, 2021 Share Posted October 17, 2021 Hi. I am making mandala book with cats. I have them as PNG but the area around the cat is white. I have to open file, click anywhere outside with magic wand click delete and save, and this action I should perform +1000 times. Is there way to automate this? I tried in Photoshop with this photoshop BG removal but it leaves white between tail and body. I would appreciate any help. Thank you. Windows 10 Latest paintNet Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 17, 2021 Author Share Posted October 17, 2021 To correct my self, what I do is click anywhere with magic wand then ctrl + I and then ctrl+shift+X. over and over. Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 17, 2021 Author Share Posted October 17, 2021 And how to set that when you click ctrl+N the resolution is 300 not 96? Quote Link to comment Share on other sites More sharing options...
otuncelli Posted October 18, 2021 Share Posted October 18, 2021 Hi @MarijaM, AFAIK, You can't do batch processing in Paint.NET. You can do it with ImageMagick though. Steps: Download & Install ImageMagick (My installation location is in C:\Program Files\ImageMagick-7.1.0-Q16-HDRI) Make sure you've a backup copy of original images. Save the code below into a .bat file and run it. It'll ask you to enter some parameters. @echo off SET /p TOLERANCE="Tolerance (Default: 20): " || SET "TOLERANCE=20" SET /p MAGICKDIR="ImageMagick Directory (Default: C:\Program Files\ImageMagick-7.1.0-Q16-HDRI): " || SET "MAGICKDIR=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI" SET /p POINT="Pick Color Point (Default: 0,0): " || SET "POINT=0,0" SET /p INPUT_DIR="Input Directory: " SET /p OUTPUT_DIR="Output Directory: " @echo on FOR %%a IN (%INPUT_DIR%\*.png) DO "%MAGICKDIR%\magick.exe" convert "%%~a" -fuzz %TOLERANCE%%% -fill transparent -draw "color %POINT% floodfill" "%OUTPUT_DIR%\%%~nxa" @echo "Done!" PAUSE Parameters Tolerance: Similar to magic wand tool's tolerance level. ImageMagick Directory: ImageMagick installation directory Point: Similar to magic wand tool's initialization point. ( Default value of 0,0 means top-left corner of the image ) Input Directory: Png files with backgrounds. Output Directory: Png files without backgrounds will be saved into this directory. 1 Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 19, 2021 Author Share Posted October 19, 2021 On 10/18/2021 at 2:40 PM, otuncelli said: Hi @MarijaM, AFAIK, You can't do batch processing in Paint.NET. You can do it with ImageMagick though. Steps: Download & Install ImageMagick (My installation location is in C:\Program Files\ImageMagick-7.1.0-Q16-HDRI) Make sure you've a backup copy of original images. Save the code below into a .bat file and run it. It'll ask you to enter some parameters. @echo off SET /p TOLERANCE="Tolerance (Default: 20): " || SET "TOLERANCE=20" SET /p MAGICKDIR="ImageMagick Directory (Default: C:\Program Files\ImageMagick-7.1.0-Q16-HDRI): " || SET "MAGICKDIR=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI" SET /p POINT="Pick Color Point (Default: 0,0): " || SET "POINT=0,0" SET /p INPUT_DIR="Input Directory: " SET /p OUTPUT_DIR="Output Directory: " @echo on FOR %%a IN (%INPUT_DIR%\*.png) DO "%MAGICKDIR%\magick.exe" convert "%%~a" -fuzz %TOLERANCE%%% -fill transparent -draw "color %POINT% floodfill" "%OUTPUT_DIR%\%%~nxa" @echo "Done!" PAUSE Parameters Tolerance: Similar to magic wand tool's tolerance level. ImageMagick Directory: ImageMagick installation directory Point: Similar to magic wand tool's initialization point. ( Default value of 0,0 means top-left corner of the image ) Input Directory: Png files with backgrounds. Output Directory: Png files without backgrounds will be saved into this directory. Will this action crop them also or just delete the white around it? I need them to be cropped. Quote Link to comment Share on other sites More sharing options...
otuncelli Posted October 19, 2021 Share Posted October 19, 2021 1 minute ago, MarijaM said: Will this action crop them also or just delete the white around it? I need them to be cropped. -trim command should do the trick. Here is the updated code. @echo off SET /p TOLERANCE="Tolerance (Default: 20): " || SET "TOLERANCE=20" SET /p MAGICKDIR="ImageMagick Directory (Default: C:\Program Files\ImageMagick-7.1.0-Q16-HDRI): " || SET "MAGICKDIR=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI" SET /p POINT="Pick Color Point (Default: 0,0): " || SET "POINT=0,0" SET /p INPUT_DIR="Input Directory: " SET /p OUTPUT_DIR="Output Directory: " @echo on FOR %%a IN (%INPUT_DIR%\*.png) DO "%MAGICKDIR%\magick.exe" convert "%%~a" -fuzz %TOLERANCE%%% -fill transparent -draw "color %POINT% floodfill" -trim "%OUTPUT_DIR%\%%~nxa" @echo "Done!" PAUSE 1 Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 19, 2021 Author Share Posted October 19, 2021 I installed it after clicking the link above but it opens something IMG display, no commands or anything. I go to folder of installation and click on magick.exe nothing happens. Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 19, 2021 Author Share Posted October 19, 2021 0 Create a desktop icon 0 Add application directory to your system path 0 Install FFmpeg 0 Associate supported file extensions with ImageMagick 0 Install legacy utilities (e.g. convert) 0 Install development headers and libraries for C and C++ 0 Install PeriMagick for Strawberry Perl v5.20 0 Install ImageMagickObject OLE Control for VBscript, Visual Basic, and WSH Quote Link to comment Share on other sites More sharing options...
otuncelli Posted October 19, 2021 Share Posted October 19, 2021 (edited) I've to admit this is a bit technical since there is not much user interface. I'll try to explain as simple as I can. After installing ImageMagick, you don't need to run anything in it. This program doesn't work that way. It has no user interface at all. Just note the location where its installed on your computer. In my case it was in C:\Program Files\ImageMagick-7.1.0-Q16-HDRI. Then download this file anywhere on your computer and run it (Basically, this is the .bat file that contains the same code above): https://drive.google.com/file/d/1xKbX9CiTdBeUz53nECjyruruNSSiy8nM/view?usp=sharing It'll ask you to enter 5 parameters. For the first 3 parameters I'm using the defaults. So I skipped those just by pressing enter key. If you installed ImageMagick into another directory than mine, you'll need to enter its path here. Then I enter input and output directories. After that, It should start to generate images in output directory. Their backgrounds are removed and cropped. Edited October 19, 2021 by otuncelli 1 Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 19, 2021 Author Share Posted October 19, 2021 It worked on some images but on images where white around is not connected, it did nothing. I think I need to enlarge images by px so the white BG is connected all around. Quote Link to comment Share on other sites More sharing options...
otuncelli Posted October 19, 2021 Share Posted October 19, 2021 Yes, I fixed it. You can use the same link to get it. It'll now first extend the canvas size by 5 percent. 1 1 1 Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 19, 2021 Author Share Posted October 19, 2021 Thank you so MUCH!!! This is amazing. Can the same program be used to resize all images to 3000×3000px or something like that? I am making clipping mask in shape of animal over set of mandala files (first test was on cats). I need the input layers for masking all to be same dimensions. Resolution doesn't matter (pixelization due to stretch or enlargement) because after all this is done I will perform Image trace and turn all in to vector. Since it is all black and white image tracing works perfectly. Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 19, 2021 Author Share Posted October 19, 2021 And just for reference, what you achieved in couple of lines this could not in 3 days of lines. Photoshop Quote Link to comment Share on other sites More sharing options...
otuncelli Posted October 20, 2021 Share Posted October 20, 2021 8 hours ago, MarijaM said: Thank you so MUCH!!! This is amazing. Can the same program be used to resize all images to 3000×3000px or something like that? I am making clipping mask in shape of animal over set of mandala files (first test was on cats). I need the input layers for masking all to be same dimensions. Resolution doesn't matter (pixelization due to stretch or enlargement) because after all this is done I will perform Image trace and turn all in to vector. Since it is all black and white image tracing works perfectly. I'm happy it worked for your case 😊 Yes, it can resize using many many different techniques. There is interpolative resizing with different modes, scaling and adaptive-resizing options. I don't know which will work best with image tracing. The example code below using "box" filter. Also converts the resulting image to 300ppi. I've also updated the link. @echo off SET /p TOLERANCE="Tolerance (Default: 20): " || SET "TOLERANCE=20" SET /p MAGICKDIR="ImageMagick Directory (Default: C:\Program Files\ImageMagick-7.1.0-Q16-HDRI): " || SET "MAGICKDIR=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI" SET /p POINT="Pick Color Point (Default: 0,0): " || SET "POINT=0,0" SET /p INPUT_DIR="Input Directory: " SET /p OUTPUT_DIR="Output Directory: " @echo on FOR %%a IN (%INPUT_DIR%\*.png) DO "%MAGICKDIR%\magick.exe" convert "%%~a" ^ -background white ^ -gravity center ^ -extent 105%%x105%% ^ -fuzz %TOLERANCE%%% ^ -fill transparent ^ -draw "color %POINT% floodfill" ^ -trim ^ -units PixelsPerInch ^ -density 300 ^ -filter box ^ -resize 3000x3000 ^ -background transparent ^ -gravity center ^ -extent 3000x3000 ^ "%OUTPUT_DIR%\%%~nxa" @echo "Done!" @echo off PAUSE 8 hours ago, MarijaM said: And just for reference, what you achieved in couple of lines this could not in 3 days of lines. Photoshop Thanks to ImageMagick developers. Photoshop's batch processing is so limited compared to it, and it's there mainly for marketing. I'm glad this forum is not as strict as Photoshop's. So we can talk about other tools and suggest alternative ways to achive something. 1 Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 20, 2021 Author Share Posted October 20, 2021 5 hours ago, otuncelli said: Thanks to ImageMagick developers. Photoshop's batch processing is so limited compared to it, and it's there mainly for marketing. I'm glad this forum is not as strict as Photoshop's. So we can talk about other tools and suggest alternative ways to achive something. Thank you. Everything worked great, now I can continue with my book. I also asked on illustrator forum how to Image trace all these photos so the interior stays white but outside is transparent and it seems that is not possible in batch, only manually. So I placed images in Powerpoint and use sharpen tool and the end result is good enough for printing. Quote Link to comment Share on other sites More sharing options...
MarijaM Posted October 21, 2021 Author Share Posted October 21, 2021 On 10/20/2021 at 5:59 AM, otuncelli said: Thanks to ImageMagick developers. Photoshop's batch processing is so limited compared to it, and it's there mainly for marketing. I'm glad this forum is not as strict as Photoshop's. So we can talk about other tools and suggest alternative ways to achive something. @otuncelli sorry to bother you, but you did open a whole new universe to me with ImageMagick and now I am looking for ways to process these images in to SVG and once again people are mentioning ImageMagick and something called Potrace Batch auto trace black and white images . Do you know something about this program and can it be used to get SVG that look the same as PNG (white interior, transparent around). I tried all kinds of settings in Illustrator and it gives me either semi white, no white or extra block around. I installed Potrace but it opens as run window so i guess once again I need come code to un inside. Quote Link to comment Share on other sites More sharing options...
Reptillian Posted October 21, 2021 Share Posted October 21, 2021 I think I have a better idea. Do what @otuncelli did, but with resize applied and lower tolerance. Then, use the alpha channel to cover up all the way to the line and process it from there. I don't know how to use ImageMagick, and I tried to do this in G'MIC. I will refer you to @otuncelli and discuss.pixls.us (if you go the g'mic route) forum for help on this Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. Link to comment Share on other sites More sharing options...
otuncelli Posted October 21, 2021 Share Posted October 21, 2021 (edited) I'm thinking of implementing something similar for my SVG File Type plugin for Paint.NET. It's currently load-only plugin. Raster to vector is a bit complex 😅 There is a --fillcolor option for potrace that you can use. (The codes below uses this) I also optimized the procedure. These codes are single step. They should do what you want from start to finish. This works but it generates squiggly lines due to upscaling algorithm. These codes are for .bat file. I also updated the link. @echo off SET /p MAGICKDIR="ImageMagick Directory (Default: C:\Program Files\ImageMagick-7.1.0-Q16-HDRI): " || SET "MAGICKDIR=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI" SET /p POTRACEDIR="PoTrace Directory (Default: Current directory)" || SET "POTRACEDIR=%cd%" SET /p INPUT_DIR="Input Directory: " SET /p OUTPUT_DIR="Output Directory: " @echo on FOR %%a IN ("%INPUT_DIR%\*.png") DO ("%MAGICKDIR%\magick.exe" convert "%%~a" ^ -background white ^ -gravity center ^ -extent 105%%x105%% ^ -fill white ^ -draw "color %POINT% floodfill" ^ -trim ^ -filter box ^ -resize 1000x1000 ^ -type grayscale ^ pnm:- | %POTRACEDIR%\potrace.exe -b svg --fillcolor #ffffff -r 32 -s -o "%OUTPUT_DIR%\%%~na.svg") @echo "Done!" @echo off PAUSE This will perform AI upscaling before vectorization process. (If source image is so small) But it requires a good GPU and this program https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.2.4. Also it takes more time to convert. @echo off SET /p MAGICKDIR="ImageMagick Directory (Default: C:\Program Files\ImageMagick-7.1.0-Q16-HDRI): " || SET "MAGICKDIR=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI" SET /p RESRGAN="Real-ESRGAN Directory (Default: Current directory): " || SET "RESRGAN=%cd%" SET /p POTRACEDIR="PoTrace Directory (Default: Current directory): " || SET "POTRACEDIR=%cd%" SET /p INPUT_DIR="Input Directory: " SET /p OUTPUT_DIR="Output Directory: " @echo on FOR %%a IN ("%INPUT_DIR%\*.png") DO ("%MAGICKDIR%\magick.exe" convert "%%~a" ^ -background white ^ -trim ^ -type grayscale ^ png:"%OUTPUT_DIR%\out.png" "%RESRGAN%\realesrgan-ncnn-vulkan.exe" -s 4 -n realesrgan-x4plus-anime -i "%OUTPUT_DIR%\out.png" -o "%OUTPUT_DIR%\upscaled.png" "%MAGICKDIR%\magick.exe" convert "%OUTPUT_DIR%\upscaled.png" ^ -resize 800x800 ^ -type grayscale ^ pnm:- | "%POTRACEDIR%\potrace.exe" -b svg --fillcolor #ffffff -r 25.6 -s -o "%OUTPUT_DIR%\%%~na.svg" del "%OUTPUT_DIR%\out.png" && del "%OUTPUT_DIR%\upscaled.png") @echo "Done!" @echo off PAUSE And there is an alternative tool for potrace named "autotrace" which supports centerline tracing. It might give you better result than potrace so you may completely skip AI upscaling step if you use it with correct parameters. But I don't know much details. Here are the results: svgfiles.zip Edited October 22, 2021 by otuncelli did some improvements 1 Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted October 21, 2021 Share Posted October 21, 2021 This is a friendly reminder that this is not an ImageMagick support forum. 5 hours ago, otuncelli said: I'm thinking of implementing something similar for my SVG File Type plugin for Paint.NET. ^^ this, or perhaps take the discussion to PM? 2 Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
otuncelli Posted October 21, 2021 Share Posted October 21, 2021 10 minutes ago, Ego Eram Reputo said: This is a friendly reminder that this is not an ImageMagick support forum. ^^ this, or perhaps take the discussion to PM? Agreed @Ego Eram Reputo. @MarijaM You can reach me with PM. 1 Quote Link to comment Share on other sites More sharing options...
MarijaM Posted November 14, 2021 Author Share Posted November 14, 2021 On 10/22/2021 at 1:03 AM, otuncelli said: Agreed @Ego Eram Reputo. @MarijaM You can reach me with PM. Thank you, and sorry for going of the main topic paint net. I truly hoped it can be done inside because I love paintnet. Sorry for delay in reply, 5 in my daughters class were positive and my daughter was sick for weeks. Now she is better and I am back at work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.