doubt on using blkproc functiom

1 vue (au cours des 30 derniers jours)
ramya raj
ramya raj le 2 Sep 2011
hai i am working with matlab R2009a and i have to move a window of size[30,700] over the image and calculate the sum of pixels inside the window
the problem is my image is having NaN values and and i am using the blkproc function to make the window move over my image and i got a matrix of size 21X700 with NAN values is my answer correct please some one help me
and my coding is this
figure ,imshow(final2); [width, height] = size(final2); fun=@sum; B=blkproc(final2,[30 height],fun);

Réponses (2)

Andrei Bobrov
Andrei Bobrov le 2 Sep 2011
variant
B=blkproc(final2,[30 height],@(x)sum(x(~isnan(x))));
OR
B=blockproc(final2,[30 height],@(block_struct)sum(block_struct.data(~isnan(block_struct.data))));
add variant
B=blkproc(final2,[30 height],@(x)sum(x(~isnan(x)&~isinf(x))))
  3 commentaires
Andrei Bobrov
Andrei Bobrov le 2 Sep 2011
Give part of your data
ramya raj
ramya raj le 2 Sep 2011
hai this is the data that i have
and the code i have used
clc;
clear all;
close all;
fundus=imread('D:\10mcs010\im0001.ppm');
grayImage=fundus(:,:,1);
[rows columns numberOfColorBands] = size(grayImage);
figure,imshow(grayImage);
title('Original Grayscale Image');
binaryImage = grayImage > 35;
A=[0 0 0;1 1 1;0 0 0];
op=imopen(binaryImage,A);
clos=imopen(op,A);
eror=imopen(clos,A);
maskedRgbImage = bsxfun(@times, fundus, cast(eror,class(fundus)));
g=maskedRgbImage(:,:,2);
imv=conv2(double(g),[1 0 -1],'same');
figure,image((imv));
title ('vertical image');
imh=conv2(double(g),[1;0;-1],'same');
figure,image((imh));
title ('horizontal image');
ev=abs(imv);
eh=abs(imh);
edgediff=imsubtract(ev,eh);
edgediff=double(edgediff);
erore=double(eror);
g=double(g);
final2=edgediff ./erore;
figure ,imshow(final2);
[width, height] = size(final2);
B=blkproc(final2,[30 height],@(x)sum(x(~isnan(x)&~isinf(x))));
and this is the answer i am getting i don't know where is the error
-44907
-13744
-9499
-1979
822
1502
-3559
12038
6991
14429
9999
8073
9060
4894
-3508
-8374
-51
-3687
-1323
-38133
0

Connectez-vous pour commenter.


Bjorn Gustavsson
Bjorn Gustavsson le 2 Sep 2011
Replace sum with nansum in your call to blkproc. If you dont have the statistics toolbox you can look for nansum in the file exchange - I've found at least one statistics-related toolbox there that includes a number of nan-safe functions.
HTH

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by