[R] Asking Favor
Michael Bedward
michael.bedward at gmail.com
Thu Sep 16 09:44:35 CEST 2010
Here's a way with less code...
# assume original matrix is X
u <- unique( sort(X) )
ucdf <- cumsum( tabulate(X)[u] )
Xcdf <- matrix(ucdf[ match(X, u) ], 8)
Michael
On 16 September 2010 14:58, chuan zun liang <chuan_zl at yahoo.com.my> wrote:
> Hello Friend:
> Thanks a lot. I kindly told that Micheal already misunderstand what i
> want.But never mind.I also can share with you what I want.
> I got a set of matrix(image) as below:
> x<-t(matrix(y,8))
>> x
> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
> [1,] 52 55 61 66 70 61 64 73
> [2,] 63 59 55 90 109 85 69 72
> [3,] 62 59 68 113 144 104 66 73
> [4,] 63 58 71 122 154 106 70 69
> [5,] 67 61 68 104 126 88 68 70
> [6,] 79 65 60 70 77 68 58 75
> [7,] 85 71 64 59 55 61 65 83
> [8,] 87 79 69 68 65 76 78 94
> y just the matrix change to vector.
> y<-c(52,55,61,66,70,61,64,73,63,59,55,90,109,85,69,72,62,59,68,113,144,104,66,73,63,58,71,122,154,106,70,69,67,61,68,104,126,88,68,70,79,65,60,70,77,68,58,75,85,71,64,59,55,61,65,83,87,79,69,68,65,76,78,94)
> Then, I want doing for histogram equalization for my image.What I want is I
> want to replace 52 by value of the cumulative distribution function. For
> example,frequency 52 is 1 and frequency for 55 is 3, so cumulative frequency
> for 55 is 4.So, I want replace 52 by 1 and 55 by 4 and so on until 94
> replace 94.
> This is the script I get(just a part for histogram equalization):
> cdfv<-function(p)
> {a<-cumsum(unlist(lapply(split(p,f=p),length)))
> b<-sort(unique(p))
> for(i in c(1:37))
> {x<-replace(x,x==b[i],a[i])}
> c(x)}
> matrix(cdfv(y),8)
> Thank you.
> Chuan
>
>
> ________________________________
> From: Michael Bedward <michael.bedward at gmail.com>
> To: chuan zun liang <chuan_zl at yahoo.com.my>; Rhelp <r-help at r-project.org>
> Sent: Wednesday, 15 September 2010 16:08:20
> Subject: Re: [R] Asking Favor
>
> Hello Chuan,
>
> If you just want a matrix with the numbers 1 to 64 arranged by row...
>
> m <- matrix(1:64, ncol=8, byrow=TRUE)
>
> But perhaps I don't understand your question properly ?
>
> Michael
>
>
> On 16 September 2010 12:46, chuan zun liang <chuan_zl at yahoo.com.my> wrote:
>> Dear Prof:
>>
>> My name is Chuan.I from Malaysia.I am a beginner for R.I need favor for
>> Prof.
>>
>> This is my data:
>>
>> y<-c(52,55,61,66,70,61,64,73,63,59,55,90,109,85,69,72,62,59,68,113,144,104,66,73,63,58,71,122,154,106,70,69,67,61,68,104,126,88,68,70,79,65,60,70,77,68,58,75,85,71,64,59,55,61,65,83,87,79,69,68,65,76,78,94)
>>
>>
>> and I form it into matrix as below: [,1] [,2] [,3] [,4] [,5] [,6] [,7]
>> [,8]
>> [1,] 52 63 62 63 67 79 85 87
>> [2,] 55 59 59 58 61 65 71 79
>> [3,] 61 55 68 71 68 60 64 69
>> [4,] 66 90 113 122 104 70 59 68
>> [5,] 70 109 144 154 126 77 55 65
>> [6,] 61 85 104 106 88 68 61 76
>> [7,] 64 69 66 70 68 58 65 78
>>
>> [8,] 73 72 73 69 70 75 83 94
>>
>> But i want replace 52 by 1, 63 by 2, 63 by 5, ........94 by 64. Is it
>> possible I
>> do it in R.Thank a lot.
>>
>> Chuan
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
More information about the R-help
mailing list