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, :).

 採用された回答

Image Analyst
Image Analyst 2019 年 6 月 16 日
編集済み: Image Analyst 2019 年 6 月 16 日

0 投票

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 件のコメント

Elder Winter
Elder Winter 2019 年 6 月 19 日
Wow, i thought the overlapping code is most easiest to understand, but i don't how to put my location in those code
Image Analyst
Image Analyst 2019 年 6 月 19 日
Again, using blockproc() to turn every pixel white is unnecessary. Even using it to turn one pixel, or a small set of pixel locations, white is not what blockproc() is supposed to be used for. Just use simple indexing, like
grayImage(y, x) = 255;
so don't try to put it into your code. It's better to just explain what you want to do and we'll tell you how to do it. I doubt turning every pixel white is what you want to do.
Elder Winter
Elder Winter 2019 年 6 月 20 日
Hmmm yeah, it's not all white, but there some gray color, it's depend the gradient color that i got from the other image. So i do as you suggest to me :
grayImage(locs(i,1)-1,locs(i,2)-1) = T{i}(1,1);
grayImage(locs(i,1),locs(i,2)-1) = T{i}(1,2);
grayImage(locs(i,1)+1,locs(i,2)-1) = T{i}(1,3);
grayImage(locs(i,1)-1,locs(i,2)) = T{i}(2,1);
grayImage(locs(i,1),locs(i,2)) = T{i}(2,2);
grayImage(locs(i,1)+1,locs(i,2)) = T{i}(2,3);
grayImage(locs(i,1)-1,locs(i,2)+1) = T{i}(3,1);
grayImage(locs(i,1),locs(i,2)+1) = T{i}(3,2);
grayImage(locs(i,1)+1,locs(i,2)+1) = T{i}(3,3);
Variable T is the gradient color as i said before.
Steven Lord
Steven Lord 2019 年 6 月 20 日
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 2019 年 6 月 20 日
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!

サインインしてコメントする。

その他の回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 16 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 16 日

0 投票

#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 件のコメント

Image Analyst
Image Analyst 2019 年 6 月 16 日
Correction, since images are accessed as image1(row, column), not image1(x, y):
image1(y-1:y+1, x-1:x+1) = 255;
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 16 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 16 日
Thank you @ImageAnalyst, Let say I have image size of 20x25, that menas it has 20 rows 25 colm
%
Again let say I want to make white pixel around the spatial coordinats (11,15), neighbour pixels only (3x3) ...............................................................................................^(r,c)
image(11-1:11+1,15-1:15+1) = 255;
Where I am doing wrong? Gratitude!
uu.png
Walter Roberson
Walter Roberson 2019 年 6 月 16 日
spatial coordinates (11,15) would typically be a statement of (x, y) coordinates, which would be column 11 row 15, leading to image1(15-1:15+1,11-1:11+1) = 255;
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 16 日
Thank you @Walter @ImageAnalyst
Elder Winter
Elder Winter 2019 年 6 月 20 日
Ohhh, it like block whole area around the point, and turn it to white. Thank You.

サインインしてコメントする。

Walter Roberson
Walter Roberson 2019 年 6 月 16 日
編集済み: Walter Roberson 2019 年 6 月 16 日

0 投票

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 件のコメント

Elder Winter
Elder Winter 2019 年 6 月 20 日
Hmmm, this looks same as above. but i want to change the center too, of course. Thank You

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by