首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在图像中旋转图像?

如何在图像中旋转图像?
EN

Stack Overflow用户
提问于 2018-07-23 05:32:53
回答 1查看 62关注 0票数 0

我正在尝试开发一个程序,可以将100x100像素的图像叠加到200x200像素的背景上。系统将提示用户移动较小的图像(左、右、上、下)和/或按任意θ值旋转CCW/CW。我的问题很简单,“如何在大图中旋转小图?”我已经尝试过在较小的图像上使用不旋转,并让较大的图像等于较小的图像。

谢谢

代码语言:javascript
复制
a = zeros(15);
b = a(7:9,7:9);

b(:) = 1; %initialize b matrix to ones
a(7:9,7:9) = b; %center matrix

    n = 1;

while n ~= 0

    n = input('PLLRAFM Aligner\n Please enter a command to align image.\n 8: up\n 2: down\n 4: left\n 6: right\n 7: rotate CCW\n 9: rotate CW\n 0: save image\n');

    switch n

    case 8 %up
     index = sub2ind(size(a),find(a == 1));
     [row, col] = ind2sub(size(a),index);
     a = zeros(15);
     row = row - 1;
     a(row,col) = 1;
     figure(2)
     imagesc(a)
    case 2 %down
     index = sub2ind(size(a),find(a == 1));
     [row, col] = ind2sub(size(a),index);
     a = zeros(15);
     row = row + 1;
     a(row,col) = 1;
     figure(2)
     imagesc(a)
    case 4 %left
     index = sub2ind(size(a),find(a == 1));
     [row, col] = ind2sub(size(a),index);
     a = zeros(15);
     col = col - 1;
     a(row,col) = 1; 
     figure(2)
     imagesc(a)
    case 6 %right
     index = sub2ind(size(a),find(a == 1));
     [row, col] = ind2sub(size(a),index);
     a = zeros(15);
     col = col + 1;
     a(row,col) = 1;    
     figure(2)
     imagesc(a)
    case 7 %rotate CCW
     index = sub2ind(size(a),find(a == 1));
     theta = 45; %temporary rotation of 1 degree
     imrotate(b,theta);
     a(b) = 1;
     figure(2)
     imagesc(a)
    case 9 %rotate CW
%      index = sub2ind(size(a),find(a == 1));
%      [row, col] = ind2sub(size(a),index);
%      theta = 45; %temporary rotation of 1 degree
%      b = imrotate(a(row,col),theta);
%      figure(2)
%      imagesc(a)
    otherwise
     fprintf('Please try again.');
    end
end

I would like to rotate this yellow block by 45 degrees for testing.

EN

回答 1

Stack Overflow用户

发布于 2018-07-23 06:51:57

如果我没理解错的话,这应该会做你想做的事情:

代码语言:javascript
复制
a=zeros(15);
b=ones(3);
b=imrotate(b,45);
a(ceil(length(a)/2)-floor(length(b)/2):ceil(length(a)/2)+floor(length(b)/2),...
    ceil(length(a)/2)-floor(length(b)/2):ceil(length(a)/2)+floor(length(b)/2))=b;
imagesc(a);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51469435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档