How to use blockproc by location?

1 vue (au cours des 30 derniers jours)
Elder Winter
Elder Winter le 16 Juin 2019
Commenté : Image Analyst le 20 Juin 2019
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, :).

Réponse acceptée

Image Analyst
Image Analyst le 16 Juin 2019
Modifié(e) : Image Analyst le 16 Juin 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 commentaires
Steven Lord
Steven Lord le 20 Juin 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 le 20 Juin 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!

Connectez-vous pour commenter.

Plus de réponses (2)

KALYAN ACHARJYA
KALYAN ACHARJYA le 16 Juin 2019
Modifié(e) : KALYAN ACHARJYA le 16 Juin 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 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 16 Juin 2019
Thank you @Walter @ImageAnalyst
Elder Winter
Elder Winter le 20 Juin 2019
Ohhh, it like block whole area around the point, and turn it to white. Thank You.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 16 Juin 2019
Modifié(e) : Walter Roberson le 16 Juin 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 commentaire
Elder Winter
Elder Winter le 20 Juin 2019
Hmmm, this looks same as above. but i want to change the center too, of course. Thank You

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by