Move Pixel
Move Pixel
Can ImageMagick move pixels to another file?
Last edited by a.s. on 2016-08-09T01:33:46-07:00, edited 2 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Randomly move pixels into a new file
I don't understand this part.a.s. wrote:So we need an algorithm to randomly take approx. 50% of all pixels away from each 1-bit BMP file and "move" them into a new, separated file.
Should the new file be the same size (pixels width and height) as the original? Should the copied pixels be in the same position as they were in the "old" file? What values should be in the other other, non-copied pixels?
snibgo's IM pages: im.snibgo.com
Re: Move Pixel
The "new" file will be of the same dimension as the source file.
Last edited by a.s. on 2016-08-09T01:39:00-07:00, edited 3 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Randomly move pixels into a new file
By "deleting" pixels, do you mean making them transparent? So the pixels in the new file that weren't copied will also be transparent?a.s. wrote:The algorithm randomly "selects" 500 pixels, stores them in a new file and deletes them in the source file.
That's easy enough, but I don't know if your BMP files will cope.
Make a mask of noise, same size as the input, where each pixel is black or white, with equal probability.
Copy all pixels from the old input to a new image.
Where the mask is white, make the new image transparent.
Where the mask is black, make the black image transparent.
Is that what you want?
snibgo's IM pages: im.snibgo.com
Re: Move Pixel
Sounds simple enough!
I will give it a try.
Thank you very much!
I will give it a try.
Thank you very much!
Last edited by a.s. on 2016-08-09T01:36:37-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Randomly move pixels into a new file
Windows BAT syntax:
This works for sRGB images. It should also work for CMYK. If it doesn't, please supply a link to a CMYK file.
Code: Select all
set SRC=toes.png
%IM%convert ^
%SRC% ^
( +clone ^
+noise Random ^
-channel R -separate +channel ^
-threshold 50%% ^
) ^
-compose CopyOpacity -composite ^
+write old.png ^
-channel A -negate +channel ^
new.png
snibgo's IM pages: im.snibgo.com
Re: Move Pixel
I failed to implement your batch into mine. The expected output should be eight files. Maybe this will be an easy fix for you?
Last edited by a.s. on 2016-08-09T01:36:17-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Randomly move pixels into a new file
Is logo.gif the same as "logo:"? If not, please provide a URL.
This works for me:
Repeat for the other colours. This processes the channels independently.
This works for me:
Code: Select all
%IMG7%magick convert ^
logo: ^
-colorspace CMYK -channel C -negate -separate -monochrome ^
( +clone ^
+noise Random ^
-channel R -separate +channel ^
-threshold 50%% ^
) ^
-compose CopyOpacity -composite ^
+write logo_C_P1.bmp ^
-channel A -negate +channel ^
logo_C_P2.bmp
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Randomly move pixels into a new file
I have now seen a sample input file test-2pass.bmp, with the required 8 outputs. The outputs have no transparency. The outputs are black where ink is needed, and white otherwise.
Each of CMYK has two images, each containing about half the required black pixels.
The input is smaller than the outputs. I don't know why. I assume they should be the same size.
Try this long Windows BAT script, to make the 8 outputs:
Each of CMYK has two images, each containing about half the required black pixels.
The input is smaller than the outputs. I don't know why. I assume they should be the same size.
Try this long Windows BAT script, to make the 8 outputs:
Code: Select all
set PREF=test-2pass
%IMG7%magick convert ^
%PREF%.bmp ^
( -clone 0 ^
-colorspace CMYK -channel C -negate -separate -monochrome ^
+write mpr:IMG ^
+noise Random ^
-channel R -separate +channel ^
-threshold 50%% ^
+write mpr:MASK ^
-delete 0 ^
mpr:IMG mpr:MASK ^
-compose Lighten -composite ^
+write %PREF%_P0_C.bmp ^
+delete ^
mpr:IMG ( mpr:MASK -negate ) ^
-compose Lighten -composite ^
+write %PREF%_P1_C.bmp ^
+delete ) ^
( -clone 0 ^
-colorspace CMYK -channel M -negate -separate -monochrome ^
+write mpr:IMG ^
+noise Random ^
-channel R -separate +channel ^
-threshold 50%% ^
+write mpr:MASK ^
-delete 0 ^
mpr:IMG mpr:MASK ^
-compose Lighten -composite ^
+write %PREF%_P0_M.bmp ^
+delete ^
mpr:IMG ( mpr:MASK -negate ) ^
-compose Lighten -composite ^
+write %PREF%_P1_M.bmp ^
+delete ) ^
( -clone 0 ^
-colorspace CMYK -channel Y -negate -separate -monochrome ^
+write mpr:IMG ^
+noise Random ^
-channel R -separate +channel ^
-threshold 50%% ^
+write mpr:MASK ^
-delete 0 ^
mpr:IMG mpr:MASK ^
-compose Lighten -composite ^
+write %PREF%_P0_Y.bmp ^
+delete ^
mpr:IMG ( mpr:MASK -negate ) ^
-compose Lighten -composite ^
+write %PREF%_P1_Y.bmp ^
+delete ) ^
( -clone 0 ^
-colorspace CMYK -channel K -negate -separate -monochrome ^
+write mpr:IMG ^
+noise Random ^
-channel R -separate +channel ^
-threshold 50%% ^
+write mpr:MASK ^
-delete 0 ^
mpr:IMG mpr:MASK ^
-compose Lighten -composite ^
+write %PREF%_P0_K.bmp ^
+delete ^
mpr:IMG ( mpr:MASK -negate ) ^
-compose Lighten -composite ^
+write %PREF%_P1_K.bmp ^
) ^
NULL:
snibgo's IM pages: im.snibgo.com
Re: Move Pixel
For some reason, the "-monochrome"-option is not respected.
Last edited by a.s. on 2016-08-09T01:37:44-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Randomly move pixels into a new file
I don't know much about different BMP types. Try "-type Palette" before each "+write".
snibgo's IM pages: im.snibgo.com
Re: Move Pixel
Thanks again.
Last edited by a.s. on 2016-08-09T01:38:05-07:00, edited 1 time in total.
Re: Move Pixel
Made it.