Move Pixel

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Move Pixel

Post by a.s. » 2016-07-27T03:19:29-07:00

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.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T03:52:03-07:00

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?
snibgo's IM pages: im.snibgo.com

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-07-27T04:00:50-07:00

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.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T04:16:41-07:00

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?
snibgo's IM pages: im.snibgo.com

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-07-27T04:23:34-07:00

Sounds simple enough!
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.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T04:33:09-07:00

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.
snibgo's IM pages: im.snibgo.com

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-07-27T05:44:41-07:00

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.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T06:07:41-07:00

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.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T07:35:07-07:00

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:
snibgo's IM pages: im.snibgo.com

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-07-27T07:50:34-07:00

Thank you.
Last edited by a.s. on 2016-08-09T01:37:09-07:00, edited 1 time in total.

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-07-27T08:29:21-07:00

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.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T08:52:09-07:00

I don't know much about different BMP types. Try "-type Palette" before each "+write".
snibgo's IM pages: im.snibgo.com

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-07-27T08:56:53-07:00

Thanks again.
Last edited by a.s. on 2016-08-09T01:38:05-07:00, edited 1 time in total.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Randomly move pixels into a new file

Post by snibgo » 2016-07-27T09:23:27-07:00

Good stuff. Glad to help.
snibgo's IM pages: im.snibgo.com

a.s.
Posts: 8
Joined: 2016-07-27T03:11:08-07:00
Authentication code: 1151

Re: Move Pixel

Post by a.s. » 2016-08-01T22:26:31-07:00

Made it.

Post Reply