Exclude point from my regression

Hi I'm doing regression with this code
I=imread('Immage.bmp')
%find the min and max
minimo= min(I(:))
massimo=max(I(:))
[r, c] = find(I>=224 & I<=225)
coefficients = polyfit(r, c, 1);
%xFit = x; % Option 1 : same number of points as the training set.
xFit = linspace(min(r), max(r), 2000); % Option 2 : lots of points, and not just where the training points are.
yFit = polyval(coefficients, xFit);
imshow(I)
hold on
plot(r, c, 'r*', 'LineWidth', 2, 'Markersize', 6)
hold on;
plot(xFit, yFit, 'm-', 'LineWidth', 5)
hold on;
line([1,2448],[1024,1024]);
'r' and 'c' are two vector thaht rappresent the coordinates (X,Y) of the pixel. I want to remove the pixel where the intensity is lower than a parameter. How can i do that?

2 Comments

You cannot remove that pixle.......but you can replace that with some other value.
I do not want to remove pixel i want to exclude them form the regression

Answers (1)

KSSV
KSSV on 5 Nov 2020
Edited: KSSV on 5 Nov 2020
Let I be your m*n image.
[m,n] = size(I) ;
[X,Y] = meshgrid(1:n,1:m) ;
[r, c] = find(I>=224 & I<=225) ;
% Get the pixel values at r, c
p = interp2(X,Y,I,r,c) ; % if it throws error comvert I into double
% Let pi be pixel values you want to remove
idx = p == pi ; % idx = abs(p-pi)<=10^-3
r(idx) = []; c(idx) =[] ; % remove those points which have pi pixel

13 Comments

I understand what you have write but i only want to remove from the vector r and c the coordinates of the pixel lower than a value
KSSV
KSSV on 5 Nov 2020
Edited: KSSV on 5 Nov 2020
[m,n] = size(I) ;
[X,Y] = meshgrid(1:n,1:m) ;
[r, c] = find(I>=224 & I<=225) ;
% Get the pixel values at r, c
p = interp2(X,Y,I,r,c) ; % if it throws error comvert I into double
% Let a be pixel values you want to remove
idx = p < a ;
r(idx) = []; c(idx) =[] ; % remove those points which have pi pixel
Whan i do Interp1 i recive the error "wrong number of input arguments" and i have converted I in double
It should be interp2. My typo error. Now I have edited the answer. Also you can pick your required pixlels using find.
Still reciv error
I=imread('Immage.bmp')
ID=double(I);
[m,n] = size(I) ;
[X,Y] = meshgrid(1:n,1:m) ;
[r, c] = find(I>=224 & I<=225)
% Get the pixel values at r, c
p = interp2(X,Y,I,r,c) % if it throws error comvert I into double
% Let a be pixel values you want to remove
idx = p < a ;
r(idx) = []; c(idx) =[] ;
Attach your image.
this is the error message:
Error using griddedInterpolant
Sample values must be of type double or single.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 136)
F = makegriddedinterp(X, Y, V, method,extrap);
this is the immage
[r, c] = find(I>=224 & I<=225) ;
If you see (r,c) they are empty. There is no value in I which is greater than 211.
For demo purpose, you can check the below code:
I=imread('Image.bmp') ;
ID=double(I);
[m,n] = size(I) ;
[X,Y] = meshgrid(1:n,1:m) ;
[r, c] = find(I>=150 & I<=180) ;
% Get the pixel values at r, c
p = interp2(X,Y,ID,r,c) ; % if it throws error comvert I into double
% Let a be pixel values you want to remove
a = 170 ;
idx = p < a ;
r(idx) = []; c(idx) =[] ;
Yes it was my error but with the right range i stil have the same error
What range you have given?
I am not getting any error....the given code is working fine.

This question is closed.

Products

Release

R2020a

Asked:

on 5 Nov 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!