java在处理过程中创建可伸缩的噪声模式
我一直在做一个Processing 3项目,创建从普通图像生成的可缩放噪声图像
该脚本获取一个普通图像,将其转换为黑白图像,然后生成两个互补的噪波图案,可以叠加以获得原始图像
我的问题是,生成的噪声模式无法缩放,即使我使用处理生成PDF格式的图像。另外,当我在Adobe Illustrator中使用图像跟踪工具时,噪声模式也不起作用
有人能提出一种方法来产生这些噪声模式,作为可缩放的噪声,可以按比例放大,而不会产生模糊的边缘吗
代码是处理中的Java模式。(代码通过图像中的所有像素运行循环,并创建黑白互补噪声模式)
//library for exporting pdf files
import processing.pdf.*;
// Processing Image objects to hold different versions of images
PImage normalSrc;
PImage blackSrc;
PImage des1;
PImage des2;
// Width and Height of all images
float imgW = 500;
float imgH = 500;
// x_position var of movable image
float x_pos = (imgW + (imgW/20))+10;
PFont tahoma;
void setup () {
//change this to normal size syntax (i.e. size(1800, 800);) to enable images to be moved around
size(1800, 800, PDF, "Output pdf image.pdf");
//Creating font for instructions
tahoma = createFont("Tahoma", 40);
textFont(tahoma);
normalSrc = loadImage("bb.jpg");
blackSrc = createImage( normalSrc.width, normalSrc.height, RGB );
des1 = createImage( blackSrc.width, blackSrc.height, RGB );
des2 = createImage( blackSrc.width, blackSrc.height, RGB );
int dimension = blackSrc.width * blackSrc.height;
blackSrc.loadPixels();
colorMode(HSB, 255, 100, 100);
//Iterating through all pixels in blackSrc
for ( int i=0; i < dimension; i+=1) {
float opacity = 150;
// if brightness of normalSrc pixel is over 50%, set blackSrc pixel to a white pixel
if ( brightness( normalSrc.pixels[i] ) > 50 ) {
blackSrc.pixels[i] = color(255);
// For white pixels in blackSrc, generate random white pixels in des1 and des2
if ( random(2) > 1) {
des1.pixels[i] = color( 0, opacity);
des2.pixels[i] = color( 0, opacity+50 );
}
// For white pixels in blackSrc generate random black pixels in des1 and des2
else
{
des1.pixels[i] = color( 255, opacity );
des2.pixels[i] = color( 255, opacity );
};
}
// if brightness of normalSrc pixel is below 50%, set blackSrc pixel to a black pixel
else
{
blackSrc.pixels[i] = color(0);
// For black pixels in blackSrc, generate complimentary black/white pixels in des1 and des2
if ( random(2) > 1) {
des1.pixels[i] = color( 0, opacity );
des2.pixels[i] = color( 255, opacity );
}
// For white pixels in blackSrc generate complimentary black/white pixels in des1 and des2
else
{
des1.pixels[i] = color( 255, opacity );
des2.pixels[i] = color( 0, opacity+100 );
};
};
}
blackSrc.updatePixels();
des1.updatePixels();
des2.updatePixels();
}
void draw () {
clear();
//background(135);
//displaying instructions
textSize(36);
text("Instructions:", 10, imgH+30);
textSize(24);
text("Drag the noise pattern using the mouse", 10, imgH+60);
text("Press RIGHT or LEFT to move noise pattern around", 10, imgH+85);
text("Press Ctrl+C to center the overlay the noise pattern on top of each other", 10, imgH+160);
image(des1, 10, 0, imgW, imgH);
image(normalSrc, (3*imgW)+(imgW/5.5), 0, imgW, imgH);
image(blackSrc, (2*imgW)+(imgW/8), 0, imgW, imgH );
// Controls for movement of des2 with mouse and keyboard
if ( keyPressed && key==CODED && keyCode==RIGHT ) {
x_pos += 1;
image(des2, x_pos, 0, imgW, imgH);
}
else if ( keyPressed && key==CODED && keyCode==LEFT) {
x_pos -= 1;
image(des2, x_pos, 0, imgW, imgH);
}
else if ( mousePressed && (mouseButton==LEFT)) {
x_pos = mouseX;
image(des2, x_pos, 0, imgW, imgH);
}
else if ( keyPressed && key=='C') { //Automatically centers the second noise on the first noise image to generate image
x_pos = 10;
image(des2, 10, 0, imgW, imgH);
}
else {
image(des2, x_pos, 0, imgW, imgH);
};
// exit() used for quitting program after saving a PDF capture
// REMOVE THIS PART OUT IF THE IMAGE IS TO BE MOVED
exit();
}
# 1 楼答案
你也在问SVG吗?包括
svg
标记。如果是这样,您应该调查image-rendering="pixelated"
。但是请注意,这是image-rendering
的一个相对较新的值,目前仅适用于Chrome和Opera