interp2 changes the value of pixels also

4 ビュー (過去 30 日間)
Golnoush Asaeikheybari
Golnoush Asaeikheybari 2019 年 5 月 19 日
編集済み: KALYAN ACHARJYA 2019 年 5 月 19 日
I am using interp2 as below to defrom my image. It imeans I want the places of some pixels change according to us and uy. The problem is that when I use interp2 it changes the value of pixels also. In my image the value of pixels are only 0, 1 , 2 , 3 but when I read the image I get after interp2 some values such as 2.67 appears also. I do not aim to change the value of pixels. I only want to change the places of pixels with the previous values (defrom the image). Why this happens and is there any other approach?
donoutdef = interp2(xx,yy,double(donut),xx+ux,yy+uy)

回答 (2 件)

Star Strider
Star Strider 2019 年 5 月 19 日
In my image the value of pixels are only 0, 1 , 2 , 3 but when I read the image I get after interp2 some values such as 2.67 appears also. I do not aim to change the value of pixels.
There are several ways to interpolate. If you want the interpolated values to be those of the closest pixel in your image, choose 'nearest' as the method. See the documentation section on method (link) for details.
You can also use the round, floor or ceil functions on fractional values to force them to the closest integer values.

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 5 月 19 日
編集済み: KALYAN ACHARJYA 2019 年 5 月 19 日
Yes, those are the interpolated values. You have the image having pixels values are 0, 1 , 2 , 3, when you interpolated new pixels, the values of new pixels are depends on method of interpolation use. I dont see any issue here.
What is original size of the image?
What image size you are expecting after resize?
  4 件のコメント
Golnoush Asaeikheybari
Golnoush Asaeikheybari 2019 年 5 月 19 日
編集済み: Golnoush Asaeikheybari 2019 年 5 月 19 日
I want each pixels goes ahead 2 times with the same value like this:
NaN NaN 0 1 0
NaN Nan 3 2 0
Or any other transformation but with exactly the same value.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 5 月 19 日
編集済み: KALYAN ACHARJYA 2019 年 5 月 19 日
>> Image=[0 1 0 1 0;1 0 3 2 0]
Image =
0 1 0 1 0
1 0 3 2 0
>> Image(:,1:2)=NaN
Image =
NaN NaN 0 1 0
NaN NaN 3 2 0
>>
or if the image is very large, then go for interpolation (nearest method) as suggested by @StarStrider.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by