Page 1 of 1

Move Pixel

Posted: 2016-07-27T03:19:29-07:00
by a.s.
Can ImageMagick move pixels to another file?

Re: Randomly move pixels into a new file

Posted: 2016-07-27T03:52:03-07:00
by snibgo
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.
I don't understand this part.

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?

Re: Move Pixel

Posted: 2016-07-27T04:00:50-07:00
by a.s.
The "new" file will be of the same dimension as the source file.

Re: Randomly move pixels into a new file

Posted: 2016-07-27T04:16:41-07:00
by snibgo
a.s. wrote:The algorithm randomly "selects" 500 pixels, stores them in a new file and deletes them in the source 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?

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?

Re: Move Pixel

Posted: 2016-07-27T04:23:34-07:00
by a.s.
Sounds simple enough!
I will give it a try.

Thank you very much! :-)

Re: Randomly move pixels into a new file

Posted: 2016-07-27T04:33:09-07:00
by snibgo
Windows BAT syntax:

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
This works for sRGB images. It should also work for CMYK. If it doesn't, please supply a link to a CMYK file.

Re: Move Pixel

Posted: 2016-07-27T05:44:41-07:00
by a.s.
I failed to implement your batch into mine. The expected output should be eight files. Maybe this will be an easy fix for you?

Re: Randomly move pixels into a new file

Posted: 2016-07-27T06:07:41-07:00
by snibgo
Is logo.gif the same as "logo:"? If not, please provide a URL.

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
Repeat for the other colours. This processes the channels independently.

Re: Randomly move pixels into a new file

Posted: 2016-07-27T07:35:07-07:00
by snibgo
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:

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:

Re: Move Pixel

Posted: 2016-07-27T07:50:34-07:00
by a.s.
Thank you.

Re: Move Pixel

Posted: 2016-07-27T08:29:21-07:00
by a.s.
For some reason, the "-monochrome"-option is not respected.

Re: Randomly move pixels into a new file

Posted: 2016-07-27T08:52:09-07:00
by snibgo
I don't know much about different BMP types. Try "-type Palette" before each "+write".

Re: Move Pixel

Posted: 2016-07-27T08:56:53-07:00
by a.s.
Thanks again.

Re: Randomly move pixels into a new file

Posted: 2016-07-27T09:23:27-07:00
by snibgo
Good stuff. Glad to help.

Re: Move Pixel

Posted: 2016-08-01T22:26:31-07:00
by a.s.
Made it.