Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Apply shear+zeropadding to an image #5149

Open
kolibril13 opened this issue Dec 21, 2020 · 1 comment
Open

Idea: Apply shear+zeropadding to an image #5149

kolibril13 opened this issue Dec 21, 2020 · 1 comment

Comments

@kolibril13
Copy link
Contributor

Description

It is already possible to shear images in skimage (example).
However, some information of the image will get lost during the shear, when the shape of the plot is preserved.
In some cases it might be useful to preserve all image information and therefore change the shape of the plot with some zero-padding.

Suggestion:

An option for padding zeros when shearing an image.

Implementation

One naive way to do so is like this:

from matplotlib import pyplot as plt
import numpy as np

from skimage import data
import cv2

camera = data.camera()
camera = cv2.cvtColor(camera, cv2.COLOR_RGB2RGBA)
plt.imshow(camera, interpolation='nearest', cmap='gray');

output_2_0

shear_factor= 1.5

pad= np.full((int(camera.shape[0]/shear_factor), camera.shape[1]) ,0)
new_pad = cv2.cvtColor(np.uint8(pad), cv2.COLOR_GRAY2BGRA)
new_pad[:,:,3]=0 # setting alpha channle to zero
camera_new=np.concatenate((camera ,new_pad) ,axis=0)
plt.imshow(camera_new, interpolation='nearest', cmap='gray');

output_3_0

camerax = []
for i,row in enumerate(np.rot90(camera_new,1)):
    camerax.append(np.roll(row,int(i/shear_factor),axis=0))
camerax=np.uint8(np.rot90(camerax,-1))
plt.imshow(camerax, interpolation='nearest', cmap='gray');

output_4_0

Further notes:

I found #1779 , #1975 and #3548 as issues and pr that also address the shear of images.

@jni
Copy link
Member

jni commented Dec 23, 2020

Thanks for raising this @kolibril13!

The real issue is that we don't have any support at all for negative coordinates, so any shear that extends into negative territory will be lost. So the way scikit-image would see your output is as a shear + translate down by ~350 pixels. This is readily expressed by an affine transform in scipy.ndimage.

Long term, I think the solution is for affine_transform to take in not just output_shape, but rather output_coordinates.

Anyway, this is all tricky and will require some careful thought for the API, but we'll definitely work on improving things here!

@scikit-image scikit-image locked and limited conversation to collaborators Oct 18, 2021
@scikit-image scikit-image unlocked this conversation Feb 20, 2022
@grlee77 grlee77 reopened this Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants