Link to the jupyter notebook containing my code is here: https://github.com/alpizano/machine-learning-neural-network/blob/master/image_processing.ipynb
So I am starting a DL neural network project and my Professor assigned that we FIRST take an image in python (+pytorch) and convert 3d matrix (rows, cols, RGB) to 2d matrix (rows,cols) by averaging (R+G+B)/3 channels to turn into grayscale, THEN to remove the background of the image by picking an intensity of a pixel, say 200, and looping/iterating thru the pixels, ex. nested for loop below:
I’m trying not to make this post too long so I can actually get help/answers (new to machine learning) but I basically grayscaled the image. Below is 1st the color image, then 2nd the gray version:
original
grayscale
So after succesfully making the grayscale image, I then made a new 2d matrix, that I initialized to the (columns, rows) 850x1332 of my image and value 255 (white?). So I then used a nested for loop to iterate thru the old gray scale matrix and COPY any pixels < 50 (black/dark colors?) to my new 2d matrix I made earlier. The for loop code & resulting image was this:
nested for loop code
supposed to have Background removed, but Foreground color also gone
![]()
My problem is that I only wanted the background removed, and you can see it’s removing the color inside the main image (Vegeto from Dragonball super).
Can anyone recommend me what steps I could take? Is it possible to iterate thru each pixel and change their RGB value of the original color img and look for a range of blues, for ex? but then i would have to change parameters for each image…
Or do I simply need to start building a neural network now and utilize object detection/segmention so it “intelligently” removes the background BUT NOT foreground?
I would greatly appreciate any help, I’ve programmed before but fairly new to the Machine learning realm, Dnn, and I really am intrigued and curious. I currently using the Getting Started with Deep
Learning Using PyTorch by Vishnu Subramanian, so I’ll take any recommendations to books, youtube videos, or online courses.