Jssor slider: How to make slider container's width and height to be fixed ratio? - slider

As the screenshot shows, the width and height value can only be px values. How can I make them to be fixed ratio such as 16:9 or 4:3?

Related

Rotating image using rotation matrix in Python

So I am trying to create a code that can rotate an image counterclockwise using Python by implementing the rotation matrix. This code is supposed to rotate the image counterclockwise, but why does it rotate the picture in a clockwise motion?
import math
import numpy as np
from PIL import Image
img = Image.open('squidward.jpg')
Im = np.array(img)
angle = 30
# Define the most occuring variables
angle=math.radians(angle) #converting degrees to radians
cosine=math.cos(angle)
sine=math.sin(angle)
height=Im.shape[0] #define the height of the image
width=Im.shape[1] #define the width of the image
# Define the height and width of the new image that is to be formed
new_height = round(abs(Im.shape[0]*cosine)+abs(Im.shape[1]*sine))+1
new_width = round(abs(Im.shape[1]*cosine)+abs(Im.shape[0]*sine))+1
# define another image variable of dimensions of new_height and new _column filled with zeros
Rot_Im=np.zeros((new_height,new_width,Im.shape[2]))
# Find the centre of the image about which we have to rotate the image
original_centre_height = round(((Im.shape[0]+1)/2)-1) #with respect to the original image
original_centre_width = round(((Im.shape[1]+1)/2)-1) #with respect to the original image
# Find the centre of the new image that will be obtained
new_centre_height= round((((new_height)+1)/2)-1) #with respect to the new image
new_centre_width= round((((new_width)+1)/2)-1) #with respect to the new image
for i in range(height):
for j in range(width):
#co-ordinates of pixel with respect to the centre of original image
y0=Im.shape[0]-1-i-original_centre_height
x0=Im.shape[1]-1-j-original_centre_width
#co-ordinate of pixel with respect to the rotated image
new_y0=round(x0*sine+y0*cosine)
new_x0=round(x0*cosine-y0*sine)
'''since image will be rotated the centre will change too,
so to adust to that we will need to change new_x and new_y with respect to the new centre'''
new_y0=new_centre_height-new_y0
new_x0=new_centre_width-new_x0
# adding if check to prevent any errors in the processing
if 0 <= new_x0 < new_width and 0 <= new_y0 < new_height and new_x0>=0 and new_y0>=0:
Rot_Im[new_y0,new_x0,:]=Im[i,j,:] #writing the pixels to the new destination in the output image
pil_img=Image.fromarray((Rot_Im).astype(np.uint8)) # converting array to image
pil_img.save("rotated_image.png") # saving the image
Do -30 for counterclockwise. I think you will get the answer but it is too late i suppose

Why resizing dataset images before CNN since it stretches them?

I initialize my dataset using the following function (simplified):
WIDTH = ...
HEIGHT = ...
def load_data(dataset_path):
images = []
labels = []
for all_images:
image = cv2.imread(pimage_path)
image = cv2.resize(image, (WIDTH, HEIGHT)) #???
labels.add(corresponding_label)
return (np.array(images).reshape(-1, WIDTH, HEIGHT, 3) / 255, np.array(labels))
In the tutorials I watched, people resize the input images to (WIDTH, HEIGHT). But this proceeds to stretch the images. I don't understand why we have to do that, because in the model I'm using the input images are applied a convolution. So I tried to not resize the input images but I got an error during the reshape process at the end of my function.
What am I missing?
You aren't limited to stretching the image, perhaps you could either crop the image or add a bufferzone with a consistent color, although if you can afford to crop the images that'd be more convenient but still you can just fill the rest of the space with a fixed color, the model would not care less.
What kind of error did you get when reshaping? Chances are that if you do not reshape the image you cannot later on resize the numpy array to WIDTH, HEIGHT. In that case, you must change the value of WIDTH and HEIGHT.

Remove the border of a sf polygon when plotted with ggplot2 using geom_sf

I'm working with a shapefile converted from a raster with lots of little holes in it, therefore, the borders create big splodges in the shape when plotted.
I'm currently adding the polygon to the main plot with the below code. Despite setting the alpha value to 1 the colours are different even when both set to "red" which makes no sense to me.
geom_sf(data = filter(db, band == 9), aes(fill = "red"), colour = "red", alpha = 1)
Can I either:
Set the borders to the same colour as the fill?
Or remove the border entirely?
Or set the border colour to none?

Draw a RoundRect in easeljs

How to draw a rectangle in easeljs with only two rounded corners. I am doing this to get rounded corners in the bottom:
layout.graphics.beginStroke("black").drawRoundRect(100,100,100,100,0,0,5,5);
This is not drawing any rounded corners. Only this seems to be working:
layout.graphics.beginStroke("black").drawRoundRect(100,100,100,100,5);
Look into the drawRoundRectComplex method, instead of drawRoundRect: http://createjs.com/docs/easeljs/classes/Graphics.html#method_drawRoundRectComplex
drawRoundRectComplex(x, y, w, h, radiusTL, radiusTR, radiusBR, radiusBL);
Hope that helps.

OpenGL glBlendFuncSeparate

I need some help with OpenGL textures masking. I have it working but need to find some other blending function parameters to work in other way.
Now I have:
//Background
...code...
glBlendFunc(GL_ONE, GL_ZERO);
...code
//Mask
...code...
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ZERO);
...code...
//Foreground
...code
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
...code
Now it sets foreground's opacity to 0 (fills with background texture) where mask is transparent. I need it to react to mask's colors. I mean something like setting foregrounds opacity depending on mask's color. For example if mask is black (0.0,0.0,0.0) then the opacity of that place in foreground is 0 (is filled with background), and if mask is white (1.0,1.0,1.0) then the opacity of foreground is 1 (not filled with background). It can be in reverse consequence (white = opacity 0, black = opacity 1). I just need it to work depending on color.
My current result's visualization bellow.
Background:
Mask (circle is transparent):
Foreground:
Result:
And I want it to work like this:
Background:
Mask (circle is white, background is black):
Foreground:
Result:
So that later it could be used like this:
Background:
Mask (circle is white, background is black):
Foreground:
Result:
Attempt with #Gigi solution:
Perhaps this is what you want:
1) Clear the destination image:
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
2) Draw the background, masking out the alpha channel:
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
3) Draw the "masking overlay", masking out the color channels:
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
4) Draw the foreground, enabling blending:
glEnable(GL_BLEND);
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE, GL_ZERO);
Note: The overlay image must have the alpha channel specified.