Help With Scaling Image Without Using Toolbox
4 ビュー (過去 30 日間)
古いコメントを表示
I am trying to scale an image using affine transformation. I am using an image of resolution 256x256. I have a code that looks something like as below :
i = imread('DIP/pic.jpg');
R = uint8(zeros(size(i)));
for x = 1:256
for y = 1:256
v = 0.25*x;
w = 0.25*y;
i(x,y) = R(v,w);
end
end
imshow(i);
imshow(R);
However whenever I run the script, I get the error Subscript indices must either be real positive integers or logicals.
I know I could just use the toolbox but I am not doing so to see how can I actually implement affine transformation as it would help me with getting a better understanding of image processing.
Thanks
0 件のコメント
回答 (2 件)
Walter Roberson
2018 年 2 月 28 日
編集済み: Walter Roberson
2018 年 2 月 28 日
Try the case of x=1 y=1. v=0.25*x so v=0.25, and likewise for w. You then try to use those 0.25 as subscripts.
5 件のコメント
Jan
2018 年 2 月 28 日
@Yawar: In "i(x,y) = R(v,w);" you overwrite the pixels of "i". It is not clear why you insert data from the zero matrix to the imported image. It it also not clear, if your input or output has 64x64 or 256x256 pixels.
Please post clearly, what you want to achieve:
- What are the inputs (size and type)
- What is the wanted output (size and type)
- By which operation do you want to achieve it?
Jan
2018 年 2 月 28 日
img = imread('DIP/pic.jpg');
x = round(linspace(1, size(img, 2), 256));
y = round(linspace(1, size(img, 1), 256));
idx = sub2ind(size(img), y, x);
R = reshape(img(idx), 256, 256);
By the way:
R = zeros(size(img), 'uint8');
is more efficient than creating a double array at first (with 8 bytes per element) and converting it to an uint8 afterwards.
4 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!