From: Arvind Prasad on
I need a program to calculate the difference in pixel values of each 1/10th part of each row of pixels. If the difference between two pixels exceeds 20% of the highest pixel value in that row, display ' Not Suitable'.
From: Walter Roberson on
Arvind Prasad wrote:
> I need a program to calculate the difference in pixel values of each
> 1/10th part of each row of pixels. If the difference between two pixels
> exceeds 20% of the highest pixel value in that row, display ' Not
> Suitable'.

Is that 1/10th distinct segments (break the row into exactly 10 pieces),
or is the 1/10th a moving window (start it at pixel 1, do the test, move
it right to pixel 2, do the test, etc.) ?

If it is distinct segments, consider blkproc()

From: Arvind Prasad on
ya break the row into exactly 10 pieces and find the difference in pixel intensities of each consecutive pixel.....
From: Walter Roberson on
Arvind Prasad wrote:
> ya break the row into exactly 10 pieces and find the difference in pixel
> intensities of each consecutive pixel.....

function pixeldiffs = tenpieces(A)

pixeldefs = 'Not suitable';
if isempty(A) || mod(size(A,2),10) ~= 0
disp('cannot break A rows into 10 equal-length pieces')
else
A20p_max = reshape( double(max(A,[],2)) ./ 5), 1, 1, []);
B = reshape(A .', [], 10, size(A,1));
Bdiff = diff(double(B),1);
Acmp = repmat(A20p_max, size(B,1), size(B,2), 1);
if any(abs(Bdiff(:)) > Acmp(:))
disp('Not suitable');
else
pixeldiffs = permute(Bdiff, [3, 1, 2]);
end
end

end


This will return either the character string 'Not suitable', or the 3D
array pixeldiffs, which will have the same number of rows as the
original image, and the columns will be the (signed) pixel differences
for one segment, with the third dimension being the 10 segments. Thus,
the pixel differences for the 3rd segment of the 4th row would be
pixeldiffs(4, :, 3) . Note that the number of elements in the difference
will be one less than the number of elements that went to make up the
segment -- e.g., if the segment ended up with 7 elements (because the
row was 70 columns wide), then the difference vector will contain 6
elements.

I don't know why you bother to break the row up in to segments if you
are going to compare the differences against the maximum for the row,
but I figure you must need the actual differences at some later
processing step. If all you really need to do is determine whether the
matrix is "suitable" or not, then the code can be made more efficient.
The only effect of breaking up into segments for the testing is to
ignore the differences that are in the columns spanning the breaks
between segments, and that ignoring could be done more efficiently by
calculating diff(A,2) and then removing the columns corresponding to the
boundary transitions, columns (size(A,2)/10) .* (1:9) of the difference
matrix. The entire resulting difference row could then be compared to
the 20% of the row maximum... there might be an efficient way to do that
in 2D using bsxfun (but bsxfun cannot be used in 3D.)