%contrast measurement
clc;
clear all;
format long;
I1=imread('image11.jpg');
I2=double(I1);
A=I2;
clear vision;
k=1;
for i=1:10:(960-96);
for j=1:10:(1280-128);
m1=max(max(A(i:i+95,j:j+127)));
m2=min(min(A(i:i+95,j:j+127)));
vision(k)=(m1-m2)/(m1);
k=k+1
end;
end;
visionk=mean(vision)

 채택된 답변

dpb
dpb 2017년 5월 4일

1 개 추천

The variable visionk ends up holding the average of a measure of the distance (max-min) scaled by the max of the subsections of the image in 96x128 rectangular areas. These areas overlap since the loops are stepping by 10 instead of by 96/128. The max(max(...)) is a common Matlab idiom to get the overall maximum of a rectangular array as max() returns the maxima by column first, then the second call finds the maximum of that vector. This lets one get the overall max/min without either a temporary or using reshape() to transform to a vector.
There's quite a lot of suprerfluous "stuff" in the loop starting with the casting to double and then assigning I2 to A; might as well have just used I1 throughout.
The one real lack that hurts performance is that vision is not preallocated so it is reallocated on every pass through the loop.
vision=zeros(ceil((960-96)/10)*ceil((1280-128)/10),1);
before the loop would be beneficial.
Minor rewrite--it would probably be better to use size() to compute the limits, but don't know that there isn't a reason for the specific magic numbers here so will leave as "exercise for the student".
I=imread('image11.jpg');
vision=zeros(ceil((960-96)/10)*ceil((1280-128)/10),1);
k=0;
for i=1:10:(960-96)
for j=1:10:(1280-128)
k=k+1;
A=I(i:i+95,j:j+127); % select the subset
m1=max(A(:)); % overall max; eliminate double call
m2=min(A(:)); % and min ditto...
vision(k)=(m1-m2)/(m1);
end
end
visionk=mean(vision);

댓글 수: 2

sahirah sabri
sahirah sabri 2017년 5월 5일
thank you sir
ElleAlba
ElleAlba 2017년 10월 19일
Salam Sahirah, dapat jwpn x dari coding berkenaan?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2017년 5월 4일

댓글:

2017년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by