Skip to main content
edited body
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

You should round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(256255 * math.sqrt(pixel[channel] / 256255))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(256255 * (pixel / 256255) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

You should round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(256 * math.sqrt(pixel[channel] / 256))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(256 * (pixel / 256) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

You should round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(255 * math.sqrt(pixel[channel] / 255))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(255 * (pixel / 255) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)
Correction by @MarkH (thanks!)
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

I find it odd that you divide and multiply by 255 instead of 256. I think youYou should also round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(256 * math.sqrt(pixel[channel] / 256))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(256 * (pixel / 256) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

I find it odd that you divide and multiply by 255 instead of 256. I think you should also round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(256 * math.sqrt(pixel[channel] / 256))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(256 * (pixel / 256) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

You should round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(256 * math.sqrt(pixel[channel] / 256))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(256 * (pixel / 256) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention.

I find it odd that you divide and multiply by 255 instead of 256. I think you should also round() the results to the nearest integer rather than truncating them towards 0.

Each of the three channels is treated identically and independently, so you shouldn't write the same code three times.

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            for channel in range(3):
                pixel[channel] = round(256 * math.sqrt(pixel[channel] / 256))
    skimage.io.imsave(output_image_file_name, image_data)

If you take advantage of the fact that channels is a NumPy array, you can vectorize the calculation.

import numpy as np
import skimage.io

def square_root_filter(input_image_file_name, output_image_file_name):
    image_data = skimage.io.imread(input_image_file_name)
    for row_data in image_data:
        for pixel in row_data:
            pixel[:] = np.rint(256 * (pixel / 256) ** 0.5)
    skimage.io.imsave(output_image_file_name, image_data)