Randomly remove pixels from an image
Randomly remove pixels from an image
I'd like to take an image and randomly remove 75% of the pixels. Can this be done?
- 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
what do you mean by "remove"? Do you mean make them transparent?
- 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
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.
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.