이미지를 특정 크기로 왜곡하지 않고 크기를 조정하고 필요할 때 패딩을 적용하는 코드 조각을 matlab에 작성했습니다.Matlab의 투명한 픽셀이있는 패드 배열
그러나 패딩은 검정색이며 투명하게 보이기를 바랍니다. 나는 이것을 어떻게하는지 모른다. 이것은 내가 가지고있는 코드입니다
% global variables
inputFolder = 'input/images/';
outputFolder = 'input/resized/';
extension = 'jpg';
x = 1000;
y = 1000;
% list all the files in the input folder
fileList = dir([inputFolder '*.' extension]);
% loop through all the files in the input folder, resize, pad and save
for i=1:length(fileList)
% get filename and load image
fname = fileList(i).name;
container = imread([inputFolder fname]);
% calculate local variables
containerY = size(container,1);
containerX = size(container,2);
containerProp = containerX/containerY;
canvasProp = x/y;
% determine proportions, apply padding and resize
if containerProp < canvasProp
container = imresize(container, [y NaN]);
containerX = size(container,2);
container = padarray(container, [0 floor((x - containerX)/2)], 0, 'pre');
containerX = size(container,2);
container = padarray(container, [0 (x - containerX)], 0, 'post');
elseif containerProp == canvasProp
container = imresize(container, [y x]);
else
container = imresize(container, [NaN x]);
containerY = size(container,1);
container = padarray(container, [floor((y - containerY)/2) 0], 0, 'pre');
containerY = size(container,1);
container = padarray(container, [(y - containerY) 0], 0, 'post');
end
% save resized image
imwrite(container, [outputFolder fname]);
end
검은 색에서 투명으로 변경하는 방법을 아는 사람이 있습니까?
죄송합니다, matlab 코드에 대한 코드 강조 표시는 실제로 작동하지 않습니다. –
첫 번째 문제는 jpeg에 투명도 채널이 없다는 것입니다. – user1071136
@ user1071136, 알아요.하지만 .png로 저장하려고합니다. 그래서 내가 추가하는 투명 픽셀이 저장됩니다. –