Lemon2311 / Lemon2311/Human_Detection_Model

Pixel Value Normalization for Grayscale Images in CNNs?

Open
#12 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted question
Dominant language
Python
Stars
4
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Hello fellow developers👾,

I'm delving into an image classification project using a CNN and encountered a preprocessing dilemma. My pipeline currently transforms RGB images into grayscale and resizes them to 80x80 pixels. However, pixel value normalization (0-1 range) has been introduced only into my predict function.

Here's a snippet from the current implementation from the mainFileTweaks-branch:

def load_and_process_images(path):
    x_data = [] 
    for img in os.listdir(path):
        if img.endswith('png'):
            pic = cv2.imread(os.path.join(path, img))
            pic = cv2.cvtColor(pic, cv2.COLOR_BGR2GRAY)  # Convert to grayscale
            pic = cv2.resize(pic, (80, 80))  # Resize to 80x80
            #pic = pic / 255.0  #Not present in code, should we normalize pixel values to [0, 1], here as well?
            x_data.append([pic])
    return x_data

def predict_image(model, image_path, image_size=(80, 80)):
    img = cv2.imread(image_path)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  # Convert to grayscale
    img = cv2.resize(img, image_size)  # Resize the image
    img = img.reshape(1, image_size[0], image_size[1], 1)  # Reshape for the model
    img = img / 255.0  # Normalization line, already present
    

does omitting normalization in such cases significantly affect CNN training efficacy, particularly for grayscale images? Are there specific scenarios where normalization isn't critical?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with load_and_process_images and predict_image on the mainFileTweaks-branch, then inspect how their outputs are fed to the CNN. Verify that the training and prediction preprocessing paths use a deliberate, matching pixel-value convention, and document or test the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
machine-learning, opencv, python
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.