标签: image-resizing

如何在调整图像大小时填充白色背景

目前的背景是黑色的.如何将颜色改为白色?

    #assuming the mime type is correct
    switch ($imgtype) {
        case 'image/jpeg':
            $source = imagecreatefromjpeg($source_image);
            break;
        case 'image/gif':
            $source = imagecreatefromgif($source_image);
            break;
        case 'image/png':
            $source = imagecreatefrompng($source_image);
            break;
        default:
            die('Invalid image type.');
    }

    #Figure out the dimensions of the image and the dimensions of the desired thumbnail
    $src_w = imagesx($source);
    $src_h = imagesy($source);


    #Do some math to figure out which way we'll need to crop the image
    #to get it proportional to the new size, then crop or adjust as …
Run Code Online (Sandbox Code Playgroud)

php gd resize-image image-resizing

9
推荐指数
1
解决办法
3万
查看次数

调整文件系统中的JPEG图像大小

有没有办法调整JPEG图像文件(从文件系统到文件系统)而不删除元数据(就像ImageMagicks 一样convert in.jpg -resize 50% out.jpg)?

我发现我调整发现.jpg文件的唯一方法是BitmapFactory.decodeStreamBitmap.compress,它看起来像一个很大的开销,如果我需要手动传输图像元数据.

android jpeg image-resizing

9
推荐指数
1
解决办法
536
查看次数

如何在Android中创建可调整大小的ImageView

我希望我的应用程序的用户能够在运行时修改图像.用户应该能够通过点击图像视图的角落并拖动它来修改图像的高度和宽度,如下图所示:

在此输入图像描述

我花了很多时间研究这个,我发现 了多点触控的感觉,并将一个大的位图文件调整为缩放输出文件,如Pinch Zoom,但这些都不符合我的要求.

目前我正在调整位图使用下面的结果和改变宽度的onprogress改变方法的搜索栏而不是帧.通过使用此功能,更改图像大小不能正常工作.

public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){

    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //The new size we want to scale to
        final int REQUIRED_WIDTH=WIDTH;
        final int REQUIRED_HIGHT=HIGHT;

        //Find the correct scale value. It should be the power of 2.
        int scale=1;
        while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
            scale*=2;

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    }
        catch (FileNotFoundException e) …
Run Code Online (Sandbox Code Playgroud)

android bitmap image-resizing

8
推荐指数
1
解决办法
1458
查看次数

双立方插值伪影(图像高级)

我正在使用双三次插值算法来升高高度图,我注意到像素边界周围的一些伪像.但是,当我使用简单的三次插值(样条曲线)时,这些伪像似乎不会出现.

可能是因为双三次插值不能保证二阶导数是连续的,不像三次样条?如果是这样,是否有已知的算法具有连续的二阶导数?否则,有没有办法处理这些工件?

线性插值(显示像素边界): 线性插值

双立方插值(在像素边界处可见的伪像): 双立方插值

立方插值(无明显伪影): 在此输入图像描述

我尝试了几个双三元公式,这给了我相同的结果.这里有些例子:


编辑:我进行了一些搜索,发现B-Spline有一个连续的C2(也是Bharat建议的).我实现了它,它看起来很好,即使它是一个近似而不是插值(它没有通过样本).

B样条(近似值): b样条

c++ interpolation image-processing bicubic image-resizing

8
推荐指数
1
解决办法
1902
查看次数

带枕头的像素化图像

我正在开展一个项目,我想把彩色网格的图片作为输入(在这个例子中用乐高积木制作)并返回一个小得多的修改图片.

这是一个示例输入:

输入

下面是一个非常小的8x8图像,结果如下:

产量

这是预期结果的更大版本:

大输出

这是我目前的代码: 它只适用于黑白图像.

from PIL import Image
import re

black = [(110,110,110),(0,0,0)] #The highest value and the lowest RGB value for the color black

img = Image.open("input.jpg") #The input image
size = (8,8) #The dimensions of the output image

out = img.resize(size,resample=Image.LANCZOS) #Resize the image

for y in range(size[0]): #loop through every pixel
    for x in range(size[1]):

        if out.getpixel((x,y)) <= black[0] and out.getpixel((x,y)) >= black[1]: #check to see if the pixel is within the accepted black …
Run Code Online (Sandbox Code Playgroud)

python image image-resizing pillow

8
推荐指数
1
解决办法
3055
查看次数

如何在Inkscape中将SVG的大小从A1调整为A0

我正在使用SVG格式的Inkscape制作海报.我在A1中设计了海报,但需要将其重新缩放为A0格式.如何进行放大?

svg vector-graphics inkscape image-resizing

8
推荐指数
1
解决办法
1万
查看次数

React Native-调整图像大小并转换为base64

所以我使用 react-native-signature-capture 来捕获签名,但我不想在编码之前减少图像大小。我使用https://github.com/bamlab/react-native-image-resizer调整图像大小,但现在我不知道如何将其转换为 base64。我尝试使用 RN 的 ImageStore,但出现图像文件路径错误。代码见下文:

ImageResizer.createResizedImage(encoded.pathName, 200, 100, 'PNG', 80, null, encoded.pathName)
  .then((resizedImageUrl) => {
    ImageStore.getBase64ForTag(resizedImageUrl, (data) => {
      console.log(data);
    }, (err) => console.log(err));
  })
  .catch((err) => console.log('failed to resize: ' + err));
Run Code Online (Sandbox Code Playgroud)

base64 image-resizing react-native

8
推荐指数
1
解决办法
4570
查看次数

调整大小时,锐利图像库会旋转图像吗?

对于node.js 使用清晰图像调整大小库https://github.com/lovell/sharp时,图像正在旋转.

我没有代码说.rotate(),为什么它被旋转,我怎么能阻止它旋转?

我使用的是由AWS提供的无服务器,图像缩放例如: https://github.com/awslabs/serverless-image-resizing使用拉姆达在飞行中调整图像如果缩略图不存在

S3.getObject({Bucket: BUCKET, Key: originalKey}).promise()
.then(data => Sharp(data.Body)
      .resize(width, height)
      .toFormat('png')
      .toBuffer()
    )
.then(buffer => S3.putObject({
        Body: buffer,
        Bucket: BUCKET,
        ContentType: 'image/png',
        Key: key,
      }).promise()
    )
.then(() => callback(null, {
        statusCode: '301',
        headers: {'location': `${URL}/${key}`},
        body: '',
      })
    )
.catch(err => callback(err))
Run Code Online (Sandbox Code Playgroud)

原始大图:

在此输入图像描述

已调整大小的图片:请注意它已被旋转:

在此输入图像描述

amazon-s3 image-resizing node.js aws-lambda sharp

8
推荐指数
2
解决办法
2144
查看次数

如何修复“在从 scipy.misc 导入此函数时无法导入名称‘imresize’的错误?

我正在使用 google colab 运行 python 代码并尝试缩小图像。

from keras.layers import Lambda
import tensorflow as tf
from skimage import data, io, filters
import numpy as np
from numpy import array
from numpy.random import randint
from scipy.misc import imresize
import os
import sys

import matplotlib.pyplot as plt
plt.switch_backend('agg')


# Takes list of images and provide LR images in form of numpy array
def lr_images(images_real , downscale):

    images = []
    for img in  range(len(images_real)):
        images.append(imresize(images_real[img],[images_real[img].shape[0]//downscale,images_real[img].shape[1]//downscale], interp='bicubic', mode=None))
    images_lr = array(images)
    return images_lr
Run Code Online (Sandbox Code Playgroud)

它应该缩小图像但显示此错误。

从 …

python scipy image-resizing

8
推荐指数
2
解决办法
2万
查看次数

PIL和OpenCV的resize有什么区别

我遇到了以下问题:这两个库的调整大小函数的行为不同。这是一个小测试:

import numpy as np
import PIL
import cv2
from matplotlib import pyplot as plt

img = np.random.randn(10, 10, 3)
SIZE = (5, 5)
img -= img.min()
img /= img.max()
img = (img*255).astype(np.uint8)

# Display the initial image
plt.figure(figsize=(16,9))
plt.imshow(img)
plt.show()
plt.close()

# resize the image in two different ways
img_cv2 = cv2.resize(img, dsize=SIZE, interpolation=cv2.INTER_LINEAR)
img_pil = PIL.Image.fromarray(img).resize(SIZE, resample=PIL.Image.BILINEAR)

# get the difference image and normalize it
diff = np.abs(img_cv2.astype(np.float32) - img_pil)
diff /= diff.max() or 1

# display results …
Run Code Online (Sandbox Code Playgroud)

python opencv image-resizing python-imaging-library

8
推荐指数
0
解决办法
3781
查看次数