Randomly remove pixels from an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
drmarie
Posts: 11
Joined: 2010-09-05T10:47:30-07:00
Authentication code: 8675308

Randomly remove pixels from an image

Post by drmarie »

I'd like to take an image and randomly remove 75% of the pixels. Can this be done?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Randomly remove pixels from an image

Post by fmw42 »

what do you mean by "remove"? Do you mean make them transparent?
drmarie
Posts: 11
Joined: 2010-09-05T10:47:30-07:00
Authentication code: 8675308

Re: Randomly remove pixels from an image

Post by drmarie »

Yes
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Randomly remove pixels from an image

Post by fmw42 »

try


convert yourimage \
\( -size 128x128 xc: +noise random -channel red -separate \
+channel -threshold 75% -transparent black \) \
-alpha off -compose copy_opacity -composite resultimage.png

The command creates a mask image of random noise in the red channel, then thresholds it so that 25% is white and 75% is black, then makes the 75% black into transparency, then puts the mask into the alpha channel of the resulting image so that 75% is transparent and 25% is the original image.
Post Reply