# Manipulate filters in arrayplot with graphical user interface

I have a set of images which need to be filtered by different filters. So I have made an interface in which the user can choose his or her filter. However I now want to manipulate the degree of the filter. Meanfilter[imagedata, {1,2,3 etc.)]. I now have a working manipulate:

Manipulate[ArrayPlot[MedianFilter[imageDataOr, i]], {i, 0, 10, 1}]


but the image does not refresh when I use it in a graphical user interface. The code is:

outM = DialogInput[{
TextCell["Adjust filter you want to use"],
Row[{Manipulate[
ArrayPlot[MedianFilter[imageDataOr, i]], {i, 0, 10, 1}]}],
Button["Continue", DialogReturn[1]]}];

image=Import["http://i.stack.imgur.com/Ekhbd.jpg"];
imageDataOr=ImageData[image]


]

EDIT: You have to grayscale the image.

To be specific. When I use the slider everything works fine, but when I click on a specific point it does not refresh

The solution is now:

butOut = DialogInput[{
TextCell["Choose the filter you want to use"],
Button["Median Filter", DialogReturn[1]]}];
If[butOut == 1, outM = DialogInput[{
TextCell["Adjust filter you want to use"],
Row[{Manipulate[
ArrayPlot[
ImageData@MedianFilter[Image[imageDataOr], ManipulateI],
PreserveImageOptions -> False], {{ManipulateI, 1, "t1"}, 0,
10, 1}, SynchronousUpdating -> True,
LocalizeVariables -> False],
Manipulate[
ArrayPlot[
ImageData@MedianFilter[Image[imageDataOr], ManipulateJ],
PreserveImageOptions -> False], {{ManipulateJ, 1, "t2"}, 0,
10, 1},
SynchronousUpdating -> True, LocalizeVariables -> False]}],
Button["Continue", DialogReturn[1]]}];
originalCorrected = MedianFilter[imageDataOr, ManipulateI];
movedCorrected = MedianFilter[imageDataMo, ManipulateJ];
];


Kind regards,

Glenn

See DialogInput > Possible Issues as a possible explanation of the freeze issue.

It is also a good idea to be aware of PreserveImageOptions which may also disconnect the control from the content.

So using the combination PreserveImageOptions->False for ArrayPlot and SynchronousUpdating -> True for Manipulate seems to fix the issue:

img = ExampleData[{"TestImage", "Tree"}];

outM = DialogInput[{TextCell["Adjust filter you want to use"],
Row[{Manipulate[ArrayPlot[ImageData@MedianFilter[img, i],
PreserveImageOptions->False], {i, 0, 10, 1},
SynchronousUpdating -> True]}],
Button["Continue", DialogReturn[1]]}]


(* you could also use ArrayPlot[MedianFilter[ImageData@img, i]] but it is painfully slow. *)

• I have tested your program but this image is also not adjusting on the manipulated value. I don't know if this is due to the running time or something.. – Glenn Oct 13 '14 at 20:49
• I see, and I have edited it now. But the problem I have now is when I don't use the slider. If I drag and drop everything works fine. But when I click on a specific point (without dragging) the image does not refresh. You know were this comes from? And when I start sliding again it does not work again and I have to restart the the evaluation – Glenn Oct 13 '14 at 20:58
• Thank you so much, it works now :)!! I have still a small question, how can I use the value of the manipulation in a new function? – Glenn Oct 13 '14 at 21:40
• @ kguler I have to add LocalizeVariables -> False in the manipulate and define the variables outside the Manipulate (make them global) I have updated the code – Glenn Oct 13 '14 at 21:49
• Glenn, we need to clean up the comments above (I will delete mine in a moment.) And please remember that if you find an answer useful, you can Upvote and/or Accept it. – kglr Oct 13 '14 at 21:54