sir im doing a simple program to identify pixel value and compare with another image,

조회 수: 1 (최근 30일)
when i run this code i am getting this error.
"Index exceeds matrix dimensions.
Error in myfu1n (line 10)
subblock = I(r:r+7, c:c+7);"
my complete code
clc;
clear all;
close all;
I = rgb2gray(imread('tablet.jpg'));
original = rgb2gray(imread('tablet1.jpg'));
original = double(original);
for( j = 0 : 1:7)
r = randi(225-7);
c = randi(225-7);
subblock = I(r:r+7, c:c+7);
imshow(subblock);
figure;
t = [1 1];
[s fval] = fminunc(@myfun , subblock)
end
y=myfun(I)
separate function
%%myfun(I)
function f = myfun(x)
scale = 0.7;
J = imresize(x, scale);
theta = 30;
x0 = imrotate(J,theta);
for( i = 1:1:225)
f = (x^2 - x0(i)^2);
end

채택된 답변

Geoff Hayes
Geoff Hayes 2017년 4월 8일
편집: Geoff Hayes 2017년 4월 8일
vani - are you sure that your image is 225x225? Rather than hardcoding the dimensions, use size to determine the number of rows and columns
numRows = size(I,1);
numCols = size(I,2);
for( j = 0 : 1:7)
r = randi(numRows - 7)
c = randi(numCols - 7);
subblock = I(r:r+7, c:c+7, 1);
% etc.
end
The 1 in subblock may not be necessary as presumably I is two dimensional (due to the conversion from RGB to grayscale).

추가 답변 (1개)

vani shree
vani shree 2017년 4월 12일
thank you sir.. its working properly im getting values. but still it is showing error in function part. Error using ^ MPOWER is not fully supported for integer classes. Both inputs must be scalar. To compute elementwise POWER, use POWER (.^) instead.
Error in myfun (line 7) f = (x^2 - x0(i) ^2);
Error in myfu1n (line 14) f = myfun(I)
can you please help me again sir
code %%myfun(I) function f = myfun(x) scale = 0.7; J = imresize(x, scale); theta = 30; x0 = imrotate(J,theta); for( i = 1:1:225) f = (x^2 - x0(i)^2); end

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by