Message Boards Message Boards

1
|
3532 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Use Arrayplot to draw unit disk?

Posted 7 years ago

I've been trying to write a program that could plot a unit circle into an image. The idea is using Arrayplot to plot the Part of pixels that fall into a disk area that radius less equal to 1.

img2 = N@Map[255 - Mean[#] &, 
ExampleData[{"TestImage", "Lena"}, "Data"], {2}];
{W, H} = Dimensions[img2];
i = Range[W]; j = Range[H];
xi = (2 i - W - 1)/W; yj = (2 j - H - 1)/H;  
radius = Sqrt[xi^2 + yj^2] ;(*These two lines are mapping each pixel to unit disk, just igrone the pixels fall out unit circle i.e. value less than -1 or greater than 1. *)
transimg2 = img2[[Round[Cases[radius, c_ /; -1 <= c <= 1]]]];
ArrayPlot[transimg2, Frame -> False]

Then got the error:

ArrayPlot::mat: Argument {{92.3333,92.3333,90.6667,92.6667,93.6667,98.,92.,93.3333,90.3333,95.,92.,95.,101.333,93.6667,95.6667,100.333,100.667,100.,94.6667,96.6667,102.,101.667,103.333,100.333,102.,99.3333,101.333,105.667,97.6667,101.333,99.,100.667,103.333,99.6667,101.667,95.,98.3333,90.,99.,89.6667,91.6667,93.,91.6667,87.,87.3333,83.6667,86.,88.,86.6667,87.3333,<<462>>},<<49>>,<<312>>} at position 1 is not a list of lists.

Please help to give some advice what may the problem in my code, thanks in advance! PS. the result I want to get is similar to the picture below (can just ignore the sphere form in this case ): enter image description here

POSTED BY: Siyad Hams
2 Replies

Your method will definitely not work; radius will be a one dimensional array. Not two dimensional. This statement:

img2[[Round[Cases[radius, c_ /; -1 <= c <= 1]]]];

also does not make much senseĀ…

Here is the correct way to implement this:

img = ExampleData[{"TestImage", "Lena"}, "Image"];
ImageTransformation[img, If[Norm[# - 0.5] < 0.5, #, {-0.1, -0.1}] &]
POSTED BY: Sander Huisman
Posted 7 years ago

Thanks a lot for your help! I went too wrong in this part.Glad you pointed that to me, thanks again!

POSTED BY: Siyad Hams
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract