Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaoer committed Oct 5, 2021
1 parent 951a236 commit b29eec7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
12 changes: 8 additions & 4 deletions catimg.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ function catimg(folder, img_type)
img_type = 'png';
end
pnglist = dir(fullfile(folder, ['*.',img_type]));
col = 10;
col = 5;
row = ceil(length(pnglist)/col);

w=0;
h=0;
for i =1:length(pnglist)
img = imread(fullfile(folder, pnglist(i).name));
[img,~, alpha] = imread(fullfile(folder, pnglist(i).name));


[im_w,im_h,c] = size(img);
if im_w>w
w = im_w;
Expand All @@ -24,10 +26,12 @@ function catimg(folder, img_type)
row_img= [];
for j=1:col
if (i-1)*col +j>length(pnglist)
background_img = ones(w,h,c);
background_img = 255*ones(w,h,c);
else
background_img = 255*ones(w,h,c);
currnet_img = imread(fullfile(folder, pnglist((i-1)*col +j).name));
[currnet_img,~,alpha] = imread(fullfile(folder, pnglist((i-1)*col +j).name));
alpha = repmat(alpha, 1,1,3);
currnet_img(alpha==0)=255;
[ci_w,ci_h,~] = size(currnet_img);
row = floor((w-ci_w)/2):(floor((w-ci_w)/2)+ci_w-1);
column = floor((h-ci_h)/2):(floor((h-ci_h)/2)+ci_h-1);
Expand Down
7 changes: 4 additions & 3 deletions compress_pdf.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ function compress_pdf(infolder,outfolder)
savename=[outfolder,tmp(1:end-3),'pdf'];
[ex,name,suffix]=fileparts(savename);
if ~exist(ex,'file')
% ex
mkdir(ex)
end
if ~exist(savename,'file')
% cmd = ['-sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=',savename,' ',Names{i}];
cmd = ['-sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true ',...
'-dDownsampleGrayImages=true ',...
'-dDownsampleMonoImages=true ',...
'-dColorImageResolution=10 ',...
'-dGrayImageResolution=10 ',...
'-dMonoImageResolution=10 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=',savename,' ',Names{i}];
'-dColorImageResolution=100 ',...
'-dGrayImageResolution=100 ',...
'-dMonoImageResolution=100 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=',savename,' ',Names{i}];
ghostscript(cmd);
end

Expand Down
47 changes: 34 additions & 13 deletions cropimg.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,41 @@ function cropimg(ModelFolder, tarfolder)
addpath('./utils')
if nargin < 2

tarfolder = [ModelFolder,'\crop'];
tarfolder = [ModelFolder,'\crop'];
end
if ~exist(tarfolder,'file')
mkdir(tarfolder);
end

[Files,Bytes,Names]=dirr(fullfile(ModelFolder,'*.png'),'name');
for i=1:length(Names)
end
[Files,Bytes,Names1]=dirr(fullfile(ModelFolder,'*.png'),'name');

[Files,Bytes,Names2]=dirr(fullfile(ModelFolder,'*.jpg'),'name');
Names = [Names1, Names2];


if exist(fullfile(ModelFolder,'mask.mat'),'file')
load(fullfile(ModelFolder,'mask.mat'))
% mask.Position = mask.Position + [-150, 840, 400, 400];
% mask.Position = mask.Position + [-150, 840, 400, 400];
img = imshow(im2double(imread(Names{1})));
else
allim = 0;
for i =1:length(Names)

if strfind(Names{i},'\crop')
continue
end
img = im2double(imread(Names{i}));
allim = allim+img;
if length(size(img))<3
img = repmat(img, 1,1,3);
end
% allim = allim+img;
if i == 1
allim = allim+img;
else
allim = do2_1(allim, img);
end
end
img = imshow(allim/max(allim(:)));
% img = imshow(allim/max(allim(:)));
img = imshow(min(allim, 1));

[rows, columns, numberOfColorChannels] = size(allim/max(allim(:)));
hold on;
Expand All @@ -36,7 +47,9 @@ function cropimg(ModelFolder, tarfolder)
line([col, col], [1, rows], 'Color', 'r');
end
mask = drawrectangle(gca);
save(fullfile(ModelFolder,'mask.mat'),'mask')
if (mask.Position(4)-mask.Position(2))*(mask.Position(3)-mask.Position(1))/(rows*columns) > 0.1
save(fullfile(ModelFolder,'mask.mat'), 'mask')
end
end

BW = createMask(mask,img);
Expand All @@ -56,7 +69,7 @@ function cropimg(ModelFolder, tarfolder)
mkdir(ex)
end
[~,name,suffix] = fileparts(Names{i});
if strcmp(suffix,'.png')
if strcmp(suffix,'.png') || strcmp(suffix,'.jpg')
[Y,~,transparency] = imread(Names{i});
if isempty(transparency)
transparency = ones(size(Y));
Expand All @@ -80,4 +93,12 @@ function cropimg(ModelFolder, tarfolder)

clear

end
end

% 变暗
function out = do2_1(bg,mix)
R = min(cat(3,bg(:,:,1),mix(:,:,1)),[],3);
G = min(cat(3,bg(:,:,2),mix(:,:,2)),[],3);
B = min(cat(3,bg(:,:,3),mix(:,:,3)),[],3);
out = cat(3,R,G,B);
end

0 comments on commit b29eec7

Please sign in to comment.