How to use blockproc by location?

1 view (last 30 days)
Hy all, is blockproc could be used to block by location(x,y) that i give? Ex: I have image with 64x64 pixels, and i want to turn white every pixel around location point(x,y), let's say i want to change [3 3] around the point. could blockproc do it? or there any suggestion for me?
Thanks, :).

Accepted Answer

Image Analyst
Image Analyst on 16 Jun 2019
Edited: Image Analyst on 16 Jun 2019
Yes, you can even do that without blockproc(). Here's how
yourImage = uint8(255 * ones(yourImage));
that will turn every pixel, at every (x,y) location, white (assuming a uint8 image).
Also, see attached demos for blockproc().
  5 Comments
Steven Lord
Steven Lord on 20 Jun 2019
There's no need to set each element individually. Address a matrix of elements on the left side of the equals sign and specify a matrix of the same size on the right.
>> A = zeros(5);
>> cent = [2, 3];
>> A(cent(1)+(-1:1), cent(2)+(-1:1)) = magic(3)
This replaces the submatrix in the first through third rows (2 + (-1:1)) and the second through fourth column (3 + (-1:1)) of A (which is a 3-by-3 submatrix of A) with the 3-by-3 magic matrix. If you don't like the negative numbers in that expression, specify the upper-left corner of the submatrix to be replaced / filled rather than the center.
>> B = zeros(5);
>> ulc = [1 2];
>> B(ulc(1)+(0:2), ulc(2)+(0:2)) = magic(3)
Image Analyst
Image Analyst on 20 Jun 2019
Elder, I don't recall you saying anything about T, the gradient color, or locs variable before your last comment above. Where did you get locs from? Why not just do a for loop over all rows in locs?
for k = 1 : size(locs, 1)
% Replace this 3x3 block with the values from T{k}:
grayImage(locs(k,1)-1:locs(k,1)+1, locs(k,2)-1:locs(k,2)+1) = T{k};
end
Make sure locs is a list (row, column) coordinates, and not (x,y), or else you won't replace the correct locations!

Sign in to comment.

More Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 16 Jun 2019
Edited: KALYAN ACHARJYA on 16 Jun 2019
#Edited
Considering Input Image is Gray, let say image1 and location of pixel is x,y
image1(y-1:y+1,x-1:x+1)=255;
  5 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 16 Jun 2019
Thank you @Walter @ImageAnalyst
Elder Winter
Elder Winter on 20 Jun 2019
Ohhh, it like block whole area around the point, and turn it to white. Thank You.

Sign in to comment.


Walter Roberson
Walter Roberson on 16 Jun 2019
Edited: Walter Roberson on 16 Jun 2019
blockproc is a waste for this kind of task, but it can be done. You would specify a blocksize of 3 x 3 and an overlap of [1 1], and then in the block_struct that is passed to your function, you would test for location == [y-1, x-1] and make the change in that case and otherwise return the input.
But there is just no point to this as you can go directly to that block.
YourImage(y-1:y+1, x-1:x+1, :) = 255; %assuming uint8
If you do not want to touch the center pixel then
YourImage(y-1:y+1, [x-1 x+1], :) = 255;
YourImage([y-1 y+1], x, :) = 255;
  1 Comment
Elder Winter
Elder Winter on 20 Jun 2019
Hmmm, this looks same as above. but i want to change the center too, of course. Thank You

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!