Im running this code on an image that is 135 by 200 pixels. thats 27000 pixels. I have 3 nested for loops that run for each pixel. (not quite, the second loop isnt run for every element in the first, and the third loop isnt run for every element in the second, but close enough)
It has been almost 20 minutes since I started running the program, and its not finished yet... How long is this going to take guys?
with both the original running and the new one running, so far it has taken 2 minutes and it has not finished the first 100 pixels. Its a duel core processor, and each thread is taking up about 50% of the total, so there isnt much room for overhead...
Nathan Foster
why would anyone need 3 nested loops for 2 dimensions
Oliver Phillips
>remove black only outside of borders
Shouldn't you first solve the problems with nogs in your own country?
Ayden Robinson
what is it supposed to do?
Christian Rogers
im trying to make all black pixels that are outside of an outline of a character. It would be really easy if all the pixels inside the border were not black, but a lot of them are. So I am checking to see if any pixel to the left or to the right is not black, and only if there are no non black pixels to both the left and right do I make the pixel in question transparent.
Juan Flores
...
Jack Powell
> running 273*109loops > wut it's been 20 minutes on my 2002 computer and it's not done yet intredasting
Juan Rivera
27^3*10^9
Owen Brown
i dont even understand you. pls explain again. pls use images
Cameron Morris
vectorize it and use numpy and PIL, this is a really inefficient way to do it
ALRI-ALRI-ALRI--- LISTEN OP I GOT THE SOLUTION FOR YOU. IM HIGH AS A CAKE BUT HERES WHAT WE HAVE SO FAR OK:
- WE HAVE A MOTHERFUCKING SPRITE, THAT HAS NO PROPER ALPHA CHANNEL SET => AROUND THE FIGURE IS BLACKNESS
NOW THIS IS WHAT OP SUGGESTED: PROGRAMMATICALLY CREATE 3 NESTED LOOPS TO REMOVE THE BLACKNESS
NOW THIS IS THE REAL SOLUTION: OPEN PHOTOSHOP AND REMOVE THE BLACK USING THE MAGIC ERASER TOOL, AND RESAVING THE SPRITE WITH PROPER ALPHA CHANNEL SET ALREADY.
THANK YOU FOR LISTENING FOLKS IT WAS A GREAT NIGHT AGAIN WITH YOU GUYS
Go through each row and fi d the first and last nonblack pixel. And make the pixels before the first nonblack pixel and after the last nonblack pixel transparent.
This isn't a very good way, but it's better than your retarded way, and I think you'll be able to manage implementing it
Jonathan Cox
outline -> flood edge wow such a damn hard filter i almost had to think matlab code incoming
John Roberts
this is unironically the solution. just implement a flood fill using bfs
Jacob Ross
That's actually not going to work like you think it would because a lot of black pixels are between two non-black.
Are you using the word 'filter' here as 'a photoshop command'?
What are you using to manipulate images? Probably has some function to do this already
Jacob Sanders
Do you want to take down all black pixels that have other black pixels *somewhere* to the right and left? Or *immediately* to the right and left? With the former, that would include all of her hair.
If you want the latter, you want to find a function that returns a pixel by coordinate. Something like `l = getPixel(sprite, getX(p) - 1, getY(p))`.
Nicholas Mitchell
OP is clearly using this as a programming exercise, not as the most efficient way of manipulating images.
Jonathan Ortiz
jesus christ just put a print every pixel how hard is that to understand?
I only want to remove a black pixel if ALL pixels to its left are black AND if ALL pixels to its right are black. So if a black pixel has a non black pixel on both its left and right, it should be un altered.
Jaxson Fisher
Maybe try dividing the image into quadrants?
In pic related, quad A: scan left to right top to bottom erasing each consecutive black pixel until you run into a nonblack pixel quad B: scan right to left, top to bottom quad C: scan left to right, bottom to top quad D: scan right to left, bottom to top
for every row: go from left to right removing everything until you see a non-white pixel also go from right to left doing the same
Wyatt Walker
Did you understand OP correctly? You can't just do convolution with a 3x3 kernel, he wants to look at every pixel in the row.
Zachary Scott
That's how the approach you described would look.
import numpy as np import PIL import PIL.Image
img = np.asarray(PIL.Image.open('test.png').convert('RGBA')).copy() target=img[0][0].copy() for r in range(img.shape[0]): for c in range(img.shape[1]): v=img[r][c]
if not np.array_equal(v,target): break
v[3]=0
for c in reversed(range(img.shape[1])): v=img[r][c]
for row in img: for pixel in row: if not np.array_equal(pixel,target): break
pixel[3]=0
for pixel in reversed(row): if not np.array_equal(pixel,target): break
pixel[3]=0
PIL.Image.fromarray(img,'RGBA').save('res.png')
Jason Howard
OP here. I have found a way to do it faster. Its still slow, but it WILL finish in probably 10 ish minutes.
I did see the issue of leaving in the black in areas I would not want to leave it. Not sure how to fix it though, so will probably just do it manually really carefully.
In retrospect, I should have just done this whole thing manually...
Michael Hernandez
The code I posted finishes in milliseconds. Doing three nested loops over all pixels for this is insane.