我想提取图像的某些部分。比方说,只有那些被某些模板或框架索引的部分。
GRAYPIC = reshape(randperm(169), 13, 13);
FRAME = ones(13);
FRAME(5:9, 5:9) = 0;
FRAME_OF_GRAYPIC = []; % the new pic that only shows the frame extracted
我可以使用for循环实现这一点:
for X = 1:13
for Y = 1:13
vlaue = FRAME(Y, X);
switch vlaue
case 1
FRAME_OF_GRAYPIC(X,Y) = GRAYPIC(X,Y)
case 0
FRAME_OF_GRAYPIC(X,Y) = 0
end
end
end
imshow(mat2gray(FRAME_OF_GRAYPIC));
但是,是否可以将它用于某种向量运算,即:
FRAME_OF_GRAYPIC = GRAYPIC(FRAME==1);
但是,遗憾的是,这不起作用。
有什么建议吗?
非常感谢您的回答, 最好, 克莱门斯
答案 0 :(得分:1)
评论太长了......
ACCOUNT_FORMS = {'login': 'switcher5.users.forms.LoginForm',
'signup': 'switcher5.users.forms.ProfileForm',
'reset_password': 'switcher5.users.forms.ResetPasswordForm'}
这里要注意三件事:
GRAYPIC = reshape(randperm(169), 13, 13);
FRAME = zeros(13);
FRAME(5:9, 5:9) = 0;
FRAME_OF_GRAYPIC = zeros(size(GRAYPIC); % MUST preallocate new pic the right size
FRAME = logical(FRAME); % ... FRAME = (FRAME == 1)
FRAME_OF_GRAYPIC(FRAME) = GRAYPIC(FRAME);
/ true()
创建,或使用false()
投射,或使用logical()
FRAME = (FRAME == true_value);
输出:
FRAME_OF_GRAYPIC(FRAME) = GRAYPIC(FRAME);