0
我想知道是否有人知道我會如何隨機刪除/刪除圖像的某些部分。是否有某種過濾器可以指定我想要刪除的圖片的百分比? (我用我的谷歌搜索來了)隨機刪除部分圖像/像素
我想知道是否有人知道我會如何隨機刪除/刪除圖像的某些部分。是否有某種過濾器可以指定我想要刪除的圖片的百分比? (我用我的谷歌搜索來了)隨機刪除部分圖像/像素
你可能是這樣的: 這不是很有效!因爲它循環選擇,然後刪除這些像素。一遍又一遍地。
我用1 MB的圖片和50%的刪除設置嘗試它花了幾分鐘。所以你被警告。
// call the source document
var srcDoc = app.activeDocument;
// Get original width and height
var imageWidth = srcDoc.width.value;
var imageHeight = srcDoc.height.value;
// Selection size for deleting pixels
// You could make these random
var sizeX = 20;
var sizeY = 20;
// Define the number of parts you want to delete
// Area of image = imageWidth * imageHeight
// Example image 1600 x 1200, area = 1920000 pixels
// To delete 50% would be the same as selecting
// an area that's (sizeX * sizeY) *2400 times
var pcent = 0.1; //10% of image
var area = imageWidth * imageHeight;
var selArea = sizeX * sizeY; //selection area
var numParts = pcent * (area/ selArea);
numParts = parseInt(numParts);
for (var i = 0; i < numParts; i++)
{
var randX = Math.floor(Math.random() * (imageWidth-sizeX));
var randY = Math.floor(Math.random() * (imageHeight-sizeY));
// deselect EVERYTHING first
srcDoc.selection.deselect();
// select random position of selection
selectRectangle(randY, randX, randY+sizeY, randX+sizeX);
// Delete those pixels
srcDoc.selection.clear();
// deselect EVERYTHING first
srcDoc.selection.deselect();
}
// function SELECT RECTANGLE(top, left, bottom, right)
//
// Note: co-ordinates are same as script listener
// and not so human-friendly as t,l,r,b.
// --------------------------------------------------------
function selectRectangle(top, left, bottom, right)
{
// =======================================================
var id1 = charIDToTypeID("setd");
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID("null");
var ref1 = new ActionReference();
var id3 = charIDToTypeID("Chnl");
var id4 = charIDToTypeID("fsel");
ref1.putProperty(id3, id4);
desc1.putReference(id2, ref1);
var id5 = charIDToTypeID("T ");
var desc2 = new ActionDescriptor();
var id6 = charIDToTypeID("Top ");
var id7 = charIDToTypeID("#Pxl");
desc2.putUnitDouble(id6, id7, top);
var id8 = charIDToTypeID("Left");
var id9 = charIDToTypeID("#Pxl");
desc2.putUnitDouble(id8, id9, left);
var id10 = charIDToTypeID("Btom");
var id11 = charIDToTypeID("#Pxl");
desc2.putUnitDouble(id10, id11, bottom);
var id12 = charIDToTypeID("Rght");
var id13 = charIDToTypeID("#Pxl");
desc2.putUnitDouble(id12, id13, right);
var id16 = charIDToTypeID("Rctn");
desc1.putObject(id5, id16, desc2);
executeAction(id1, desc1, DialogModes.NO);
}
怎麼樣溶解? – Strawberry 2014-11-07 01:11:18
您能更具體地瞭解「隨機」您可以編寫一個函數,在隨機位置和隨機大小中進行選擇(重複多次)以擦除這些像素。或者只是交換圖層以解散 – 2014-11-07 11:16:49