Azzera filtri
Azzera filtri

After division i am getting 1 as the answer

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Jan
Jan il 17 Set 2017
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.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 17 Set 2017
Cast c1 to double so that you're not doing an integer divide, but doing a floating point divide instead:
c2 = double(c1) / 256;

Più risposte (1)

Jan
Jan il 17 Set 2017
Modificato: Jan il 17 Set 2017
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 Commento
Udit Jain
Udit Jain il 17 Set 2017
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
>>

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by