フィルターのクリア

After division i am getting 1 as the answer

2 ビュー (過去 30 日間)
Udit Jain
Udit Jain 2017 年 9 月 17 日
コメント済み: Udit Jain 2017 年 9 月 17 日
editor:
f1=input('Enter a image name:','s');
a1=imread(f1);
c1=rgb2gray(imresize(a1,[3,9]))';
N=[208 16 235 255 44 229 236 34 247;...
245 21 213 254 55 252 215 51 249;...
248 22 225 252 30 240 242 27 244]';
N=N/256
c2=c1/256
Command window: Enter a image name:51.jpg
N =
0.8125 0.9570 0.9688
0.0625 0.0820 0.0859
0.9180 0.8320 0.8789
0.9961 0.9922 0.9844
0.1719 0.2148 0.1172
0.8945 0.9844 0.9375
0.9219 0.8398 0.9453
0.1328 0.1992 0.1055
0.9648 0.9727 0.9531
c2 =
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
>>
  1 件のコメント
Jan
Jan 2017 年 9 月 17 日
I've marked the code with the mouse and pressed the "{} Code" button to make the code readable. Please do this by your own in the future. Thanks.

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

採用された回答

Image Analyst
Image Analyst 2017 年 9 月 17 日
Cast c1 to double so that you're not doing an integer divide, but doing a floating point divide instead:
c2 = double(c1) / 256;
  1 件のコメント
Udit Jain
Udit Jain 2017 年 9 月 17 日
Thanks for your help

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

その他の回答 (1 件)

Jan
Jan 2017 年 9 月 17 日
編集済み: Jan 2017 年 9 月 17 日
What is your question? Does the result differ from your expectation? Then explain, what you expect instead, because the readers cannot guess this detail. Of course the code does exactly what it should.
a1 = imread(f1);
a2 = imresize(a1, [3,9]);
c1 = rgb2gray(a2)';
Check the contents of the variables:
class(a1)
class(a1)
class(c1)
a1(1, 1, :)
a2(1, 1, :)
c1(1)
c1(1) / 256
What do you see?
  1 件のコメント
Udit Jain
Udit Jain 2017 年 9 月 17 日
c1 is a matrix with integers according to the reshape and N is a matrix with some integers. When N is divided by 256 it gives some decimal values while on dividing c1 by 256 it gives 1 as answer for all divisions.
class(a1)
ans =
uint8
>> class(a2)
ans =
uint8
>> class(c2)
ans =
uint8
>> a1(1, 1, :)
ans(:,:,1) =
255
ans(:,:,2) =
255
ans(:,:,3) =
255
>> a2(1, 1, :)
ans(:,:,1) =
254
ans(:,:,2) =
254
ans(:,:,3) =
254
>> c1(1)
ans =
254
>> c1(1) / 256
ans =
1
>>

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

Community Treasure Hunt

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

Start Hunting!

Translated by