Finding a matrix to shift an image

53 ビュー (過去 30 日間)
Michelle
Michelle 2020 年 11 月 15 日
回答済み: Sourabh Kondapaka 2020 年 11 月 18 日
How do i find a matrix that would shift an image horizontally by 240 pixels and how do i display it using a spy function?
Below is the code I have for turning the image into a matrix and I have also attached the image to this post
% Read the image
img1 = imread('mountain.jpg');
% Convert it to double
img1Double = im2double(img1);

回答 (1 件)

Sourabh Kondapaka
Sourabh Kondapaka 2020 年 11 月 18 日
If you want to just shift the image horizontally, you can use the function imtranslate() as shown:
im1 = imread('mountain.jpg');
figure(1);
imshow(im1);
figure(2);
%Translate by 240 pixels on the X-axis
im1 = imtranslate(im1, [240 0]);
imshow(im1);
spy(S) plots the sparsity pattern of matrix S. Nonzero values are colored while zero values are white. The plot displays the number of nonzeros in the matrix.
To show spy() values you can check the following
im1 = imread('mountain.jpg');
figure(1);
im1Double = im2double(im1);
spy(im1Double);
figure(2);
im1 = imtranslate(im1, [250 0]);
spy(im1Double);

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by