我有一组450jpg的图像,每个大约1200x1500像素。我想要为每个图像应用一个黑色边框,使它们全部为1500x1500像素。
下面是一个示例图像:test01.jpg,我想将其转换为如下所示的as图像:1500x1500 image with border
我一直在尝试的方法是在原始图像上叠加一个black border的png图像。然而,这并不是很有效:(到目前为止,我的代码如下:
A = imread('test01.jpg'); %open image
A2 = imresize(A,[1500 1200]); %resize image to 1500 x 1200 just to make sure it is correct height
RA = imref2d(size(A2));
B = imread('cropper_and_outline_1500x1500.png'); %open cropper
RB = imref2d(size(B));
C = imfuse(A2,B,'blend','Scaling','joint'); %fuse images
imshow(C)
这是我的current output。有几个错误...a)黑色边框不是不透明的,b)透明颜色设置为绿色而不是透明,c)两个图像在左上角对齐,但我需要它们居中对齐。
我一直在玩阿尔法水平,试图修复果岭,但我并不是真的理解它的意思,所以没有走远!我也知道这可能不是最简单的方法,所以如果有人有其他想法,我真的很想听听。我正在尝试在MATLAB中这样做,因为我已经有一个用于重命名文件的脚本,理想情况下,我希望将这两个脚本合并为一个脚本。
非常感谢!
发布于 2021-05-06 19:21:46
为什么不在原始图像中添加黑色线条呢?
I = imread(yourfile);
expectedSize = [1500, 1500];
% Add horizontal lines of pixels (if needed)
line1 = zeros(1, size(I, 2));
Im = [repmat(line1, [(expectedSize(1) - size(I, 1))/2, 1, 3]); ... % add lines on top
I; ...
repmat(line1, [(expectedSize(1) - size(I, 1))/2, 1, 3])]; % add lines on the bottom
% Add vertical lines of pixels (if needed)
line2 = zeros(size(Im, 1), 1);
Im = [repmat(line2, [1, (expectedSize(2) - size(Im, 2))/2, 3]), ... % add lines to the left
Im, ....
repmat(line2, [1, (expectedSize(2) - size(I, 2))/2]), 3]; % add lines to the right
好吧,这是在假设expectedSize(i) - size(I, i)
的结果可以被2整除的情况下完成的,但是你明白了……
https://stackoverflow.com/questions/67416402
复制相似问题